PHP 7: extended function libraries-file systems, processes, and networks

Source: Internet
Author: User
Tags rewind mx record

The PHP Extension function library is very large. It is officially unofficial. Here we only record some commonly used extensions. For this part, we only record some of the core functions, not a full record. For detailed descriptions of extended functions, You need to refer to the PHP user manual in use.

1. Directory operations
Dir () returns a directory object
Read () traverses entries in the directory object

<?php$d=dir("./");while($item=$d->read()){        echo $item;        echo "\n";}$d->rewind();$d->close();?>

2. File System Operations

Dirname () returns the directory name section in the path.
Basename () returns the part of the file name in the path.
Chown chgrp chmod is similar to a Linux system call with the same name.
Mkdir copy rename Delete unlink tmpname touch tmpfile umask is similar to a Linux system call with the same name.
Disk_free_space () disk_total_space ()
Fopen fread fwrite feof fflush fclose fseek ftell rewind and other functions similar to C standard library functions with the same name
File_exists () check whether the file and directory exist
File () reads the entire file into an array, and each subscript corresponds to a row of the file
File_get_contents () reads the entire file into a string and supports reading several characters from a specific position of the file.
File_put_contents ($ file, $ data) writes string data to the specified file
Readfile () readlink directly outputs file or link content
Fileatime filemtime filectime: Last access/modification of the file/inode modification time
Fileowner filegroup: returns the file owner and group number.
Filesize filetype fileperms obtains the file size, type, and permissions.
Fputcsv fgetcsv reads CSV data from a file or writes CSV data to a file
Fstat ftruncate: Get the stat information of the file corresponding to the pointer/truncate to the specified length
Stat obtains the stat information of a file based on the file name.
Is_dir is_file is_link is_executable is_readable is_writeable is_uploaded_file
Move_uploaded_file
Parse_ini_file parse_ini_string parses the INI file and string and returns an associated data. You can access related configuration items by name.
Pathinfo returns the associated array, including dirname, basename, extname, filename
Popen pclose open/close pipeline file pointing to process
Realpath () returns the absolute path

3. Process Control
3.1 POSIX Extension

Posix_access ($ file, $ mode) allows you to view the object access permissions, which can be replaced by several functions such as is_readable.
Posix_errno () returns the previous POSIX function execution error
Posix_getcwd () returns the current directory, which is the same as getcwd ().
Posix_getgid () geteuid () getgid () getegied () getgroup () getpgid () getpgrp () getpid () getsid and other similar Linux system calls with the same name
Posix_getlogin () Get the logon name
Posix_getpwnam () get user details
Posix_getrlimit () to obtain resource limits
Posix_kill () posix_times ()
3.2 program execution functions
String exec ($ cmd, array & $ output, Int & $ return_var) executes the external program and returns the last line of output.
String shell_exec ($ cmd) is the same as the 'cmd' function.
String System () executes the command and displays the output. The returned value is the last line of the output.
The escapeshellarg () Escape string is used as the shell parameter.
Escapeshellcmd () Escape Character as shell command
Proc_open () executes the program and opens a pipeline to read and write the corresponding input and output.
Proc_nice () adjusted program priority
Proc_close () Close the opened Program
Proc_terminate () Terminate the opened Program

3.3 semaphores, IPC, and shared memory

Resource sem_get (INT $ key, [int $ max_acquire = 1 [, int $ perm = 0666 [, int $ auto_release = 1]) returns a System V semaphore, it is created for the first call, and different identifiers are returned for subsequent calls, but the same semaphore is accessed.
Bool sem_remove (resource $ handler) removes the specified semaphore from the system, and then cannot be accessed.
Bool sem_acquire ($ handler) is blocked until the semaphore is obtained
Bool sem_release ($ handler) to release the semaphore obtained before

Resource msg_get_queue (INT $ key [, int $ perms = 0666]) returns a System V message queue by key. It is created for the first call, and different identifiers are returned for subsequent calls, but they all access the same message queue.
Boo msg_remove_queue ($ handler) removes the system's message queue, and the process will not be able to access it again
Bool msg_send ($ queue, int $ msg_type, $ MSG [, bool $ serialize = true [. bool $ blocking = true [, Int & $ errcode]) to store a message
Msg_recvive ($ queue, int $ expect_type, & $ msgtype, $ maxsize, & $ MSG [, bool $ unserialize = true [, $ flag = 0 [, & $ errcode]) extracts a message from the message queue.
Array msg_stat_queue ($ handler)
Bool msg_set_queue () is used to set relevant attributes on a message.

Resource shm_attach ($ key, $ perms) returns a System V shared memory by key. It is created for the first call, and different identifiers are returned for subsequent calls, but they all access the same message queue.
Bool shm_remove ($ handler) removes shared memory objects from the system
Bool shm_detach ($ handler) is disconnected from the shared memory object, but there are still related objects in the system.
Bool shm_put_var ($ hanlder, $ key, $ Val) sets data to the shared memory
Mixed shm_get_var ($ handler, $ key) retrieves data from the shared memory
Bool shm_remove_var ($ handler, $ key) removes data from the shared memory


 4. Network Expansion
4.1 URL Extension

String base64_decode ($ Str) returns the original string
String base64_encode ($ Str) returns the encoding string
Array get_headers ($ URL, $ B _hash) returns the response header of the specified URL server. If $ B _hash is true, the associated array is returned.
String http_build_query (array $ data) encodes the hash array data into a request string after HTTP
String rawurlencode ($ Str) encode the URL according to rfc1738
String rawurldecode ($ Str) decodes the URL

<?php$data = array('foo'=>'bar',              'baz'=>'boom',              'cow'=>'milk',              'php'=>'hypertext processor');              echo http_build_query($data); // foo=bar&baz=boom&cow=milk&php=hypertext+processor$url = 'http://username:password@hostname/path?arg=value#anchor';print_r(get_headers($url));/*Array(    [scheme] => http    [host] => hostname    [user] => username    [pass] => password    [path] => /path    [query] => arg=value    [fragment] => anchor)*/

4.2 Socket Extension

Resource socket_create ($ domain, $ type, $ protocol) returns a socket Descriptor
Socket_bind ($ sock, $ IP, $ port) set binding
Socket_listen ($ socket, $ backlog) listening port
Resource socket_accept ($ sock)
Resource socket_connect ($ sock, $ IP, $ port) connects to the remote address and port
String socket_read ($ sock, $ length) reads data from the socket
Int socket_write ($ sock, $ STR, $ Len) writes data from the socket
Int socket_recv/send ($ sock, $ & Buf, $ Len, $ flag) receives and sends data from the socket
Socket_recvfrom/sendto ($ sock, $ & Buf, $ Len, $ flag, $ & IP, $ & Port)
Socket_get/set_option ($ sock, $ level, $ optname, [$ optname]) sets socket options
Socket_set_nonblock ($ sock) is set to non-blocking.
Socket_getpeer/sockname ($ sock, $ & IP, $ & Port)
Socket_strerror ($ errno)
Socket_clear_error ($ sock)

4.3 Network Tools
Array dns_get_record ($ hostname, $ type, $ & auth_ns, $ & additional) obtains the DNS records of host names of the corresponding type, and returns the authentication ns and additional information.
Bool dns_check_record ($ name, $ type)/checkdnsrr type has MX, A, any, AAAA, all. If the corresponding record is found, t is returned; otherwise, F is returned.
Dns_get_mx/getmxrr ($ host, array $ & mxlist) Get the MX record of the corresponding host
Resource fsockopen ($ IP, $ port) returns a network connection, which is equivalent to running socket_create and socket_connect
String gethostbyaddr ($ IP) gethostbyname1 ($ host) returns the corresponding domain name or address. If a function with 1 is used, an address array is returned.
Getprotobyname/number ()
Getservbyname ()/getservbyport ()
String inet_ntop ($ in_addr)
String inet_ton ($ IP)
Long2ip ()/ip2long ()
Setsookie/setrawcookie ($ name, $ Val, $ expier, $ domain ,)
Socket_get_status ()
Socket_set_timeout ()

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.