Reprint: PHP Extension Library-file system, process and network

Source: Internet
Author: User

PHP's extension library is huge, official unofficial, here only to record some of the more commonly used extensions, for this part, just record some of the core functions, not a comprehensive record. For a detailed description of the extension function, you need to refer to the PHP user manual in use.

1 Directory Operations
Dir () returns a directory object
Read () traverse the entries in the directory object

1<?PHP2 $d=dir("./"); 3   4   5  while($item=$d-read ())6 {  7         Echo $item; 8         Echo"\ n"; 9 }  Ten    One    A $d-Rewind();  - $d-Close ();  -?>

2 File system Operation

DirName () returns the directory name portion of the path
BaseName () returns the file name portion of the path
Chown chgrp chmod is similar to a Linux system call with the same name
mkdir mkdir Copy Rename delete unlink Tmpname touch tmpfile umask similar to Linux system calls with the same name
Disk_free_space () Disk_total_space ()
fopen fread fwrite feof fflush fclose fseek Ftell Rewind are similar to the functions of the C standard library function with the same name
File_exists () Check the existence of files and directories
File () reads the entire document into an array, one row of each subscript corresponding to the file
File_get_contents () reads the entire file into a string, supporting the reading of several characters starting at a specific location in the file
File_put_contents ($file, $data) writes string data to the specified file
ReadFile () readlink outputs the file or link content directly
Fileatime filemtime Filectime Last access/modification of file/inode modification time
Fileowner Filegroup Returns the number of the file owner and group
FileSize filetype fileperms Get the file size, type, permissions
Fputcsv fgetcsv reading data from a file in CSV format or writing CSV format data to a file
Fstat Ftruncate Gets the stat information of the pointer corresponding to the file/truncated to the given length
Stat Gets the stat information of the file based on the filename
Is_dir is_file is_link is_executable is_readable is_writeable is_uploaded_file Determine the properties of a file
Move_uploaded_file
Parse_ini_file parse_ini_string Parse INI file and string, return an association data, can access related configuration item by name
PathInfo returns an associative array that contains the dirname,basename,extname, filename
Popen Pclose Open/Close a pipeline file pointing to a process
Realpath () returns the absolute path

The feof () function detects whether the end of the file has been reached (EOF)

3 Process Control
3.1 POSIX extension

Posix_access ($file, $mode) View the access rights of a file, can be replaced by several functions such as is_readable
Posix_errno () returns the last error that the POSIX function performed
POSIX_GETCWD () returns the current directory, same as GETCWD ()
Posix_getgid () Geteuid () Getgid () getegied () Getgroup () Getpgid () getpgrp () Getpid () GetSID are similar to Linux system calls with the same name
Posix_getlogin () Get login name
Posix_getpwnam () get user's details
Posix_getrlimit () Get 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 the output
String Shell_exec ($cmd), like the ' cmd ' function, returns all output from the program
String System () executes the command and displays the output with the return value as the last line of the output
Escapeshellarg () escapes the string as a shell parameter
Escapeshellcmd () escape character utilises as shell command
Proc_open () executes the program and opens a pipe for reading and writing the appropriate inputs and outputs
Proc_nice () Adjust the priority of the program
Proc_close () Close the Open program
Proc_terminate () Terminate open 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 the semaphore of a System V, which is created when first called, Subsequent invocations return different identifiers, but each have access to the same semaphore.
BOOL Sem_remove (Resource $handler) removes the specified semaphore from the system and is no longer accessible
BOOL Sem_acquire ($handler) blocks until the semaphore is acquired
BOOL Sem_release ($handler) The amount of semaphore obtained before releasing

    resource Msg_get_queue (int $key [, int $perms = 0666])   Returns a message queue of System V by key. The first call is created, and subsequent calls return different identifiers, but both access the same message queue.
    Boo Msg_remove_queue ($handler)   Remove Message Queuing from the system, after which the process will no longer be accessible
    bool Msg_ Send ($queue, int $msg _type, $msg [, BOOL $serialize =true[. BOOL $blocking =true [, int & $errcode]])   Deposit a message to a message
    msg_recvive ($queue, int $expect _type, & $msgtype, $maxsize, & $msg [, bool $unserialize = True [, $flag = 0 [,& $errcode]])   Take a message out of message queue
    array msg_stat_queue ($handler)  & nbsp View related properties on Message Queuing
    bool  msg_set_queue ()   Set related properties on messages     

Resource Shm_attach ($key, $perms) press key to return a System V shared memory. The first call is created, and subsequent calls return different identifiers, but both access the same message queue.
BOOL Shm_remove ($handler) removing 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) setting data to shared memory
Mixed Shm_get_var ($handler, $key) accessing data from within a share
BOOL Shm_remove_var ($handler, $key) removing data from shared memory


4 Network Extensions
4.1 URL Extension

String Base64_decode ($STR) returns the original string
String Base64_encode ($STR) returns the encoded string
Array get_headers ($url, $b _hash) returns the response header of the specified URL server and, if $b_hash is true, returns the associative array
String Http_build_query (array $data) encodes hash array data to the request string after HTTP
String Rawurlencode ($str) encodes a URL based on RFC1738
String Rawurldecode ($STR) to decode the URL
<?PHP$data=Array(' foo ' = ' bar ', ' baz ' = ' boom ', ' cow ' = ' milk ', ' php ' = ' hypertext Processo R); Echo Http_build_query($data);//Foo=bar&baz=boom&cow=milk&php=hypertext+processor$url= ' Http://username:[email protected]/path?arg=value#anchor ';Print_r(get_headers($url));/*Array ([scheme] + HTTP [host] + hostname [user] = username [pass] = password [path] =&G T /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 bindings
Socket_listen ($socket, $backlog) listening port
Resource Socket_accept ($sock)
Resource Socket_connect ($sock, $ip, $port) connecting remote addresses and ports
String Socket_read ($sock, $length) reads data from the socket
int Socket_write ($sock, $str, $len) write data from the socket
int Socket_recv/send ($sock, $&buf, $len, $flag) receive and send data from the socket
Socket_recvfrom/sendto ($sock, $&buf, $len, $flag, $&ip,$&port)
Socket_get/set_option ($sock, $level, $optname, [$optname]) Set 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 networking tools
Array Dns_get_record ($hostname, $type, $&auth_ns,$&additional) gets the DNS record for the hostname of the corresponding type, which returns the authentication NS and additional information
BOOL Dns_check_record ($name, $type)/CHECKDNSRR type has Mx,a,any,aaaa,all and returns t if the corresponding record is found, otherwise f
DNS_GET_MX/GETMXRR ($host,array$& mxlist) get the MX record for the corresponding host
Resource Fsockopen ($IP, $port) returns a network connection that is equivalent to running socket_create and Socket_connect
String gethostbyaddr ($ip) gethostbyname1 ($host) returns the corresponding domain name or address, and if a function with 1 is used, an array of addresses is returned
Getprotobyname/number ()
Getservbyname ()/getservbyport ()
String Inet_ntop ($in _addr)
String Inet_pton ($IP)
Long2ip ()/ip2long ()
Setsookie/setrawcookie ($name, $val, $expier, $domain,)
Socket_get_status ()
Socket_set_timeout ()

Original link: http://blog.csdn.net/zzulp/article/details/7749866

Website Link: http://php.net/manual/zh/refs.fileprocess.process.php

Reprint: PHP Extension Library-file system, process and network

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.