Currently, php provides the most comprehensive CURL description in Chinese _ PHP Tutorial

Source: Internet
Author: User
Tags ftp commands http 200 http authentication random seed
Currently, php provides the most comprehensive CURL description in Chinese. In PHP, the CURL Function Library (ClientURLLibraryFunction) curl_close-closes a curl session curl_copy_handle-copies all content of a curl connection resource and the CURL Function in the curl_errno-PHP file)

Curl_close-close a curl session
Curl_copy_handle-copy all content and parameters of a curl connection resource
Curl_errno-a number containing the current session error message is returned.
Curl_error-returns a string containing the current session error message.
Curl_exec-execute a curl session
Curl_getinfo-obtains the information of a curl connection resource handle.
Curl_init-initialize a curl session
Curl_multi_add_handle-add a separate curl handle resource to the curl batch processing session
Curl_multi_close-close a batch processing handle resource
Curl_multi_exec-parse a curl batch handle
Curl_multi_getcontent-return the obtained output text stream
Curl_multi_info_read-obtains the transmission information of the currently resolved curl.
Curl_multi_init-initialize a curl batch processing handle resource
Curl_multi_remove_handle-remove a handle resource from the curl batch processing handle.
Curl_multi_select-Get all the sockets associated with the cURL extension, which can then be "selected"
Curl_setopt_array-set session parameters for a curl in the form of an array
Curl_setopt-set session parameters for a curl
Curl_version-obtain curl-related version information

The function curl_init () initializes a curl session. the unique parameter of the curl_init () function is optional, indicating a url address.
The role of the curl_exec () function is to execute a curl session. the unique parameter is the handle returned by the curl_init () function.
The function curl_close () is used to close a curl session. the only parameter is the handle returned by the curl_init () function.

$ Ch = curl_init ("http://www.baidu.com /");
Curl_exec ($ ch );
Curl_close ($ ch );
?>

The curl_version () function is used to obtain the version information related to curl. the curl_version () function has a parameter and it is unclear what it is.

Print_r (curl_version ())
?>

The curl_getinfo () function is used to obtain information about a curl connection resource handle. the curl_getinfo () function has two parameters. The first parameter is the curl resource handle, the second parameter is the following constants:

$ Ch = curl_init ("http://www.baidu.com /");
Print_r (curl_getinfo ($ ch ));
?>

Optional constants include:

CURLINFO_EFFECTIVE_URL
Last valid url address

CURLINFO_HTTP_CODE
The last received HTTP code

CURLINFO_FILETIME
The time when the document is obtained remotely. if the document cannot be obtained, the returned value is "-1"

CURLINFO_TOTAL_TIME
Time consumed by the last transmission

CURLINFO_NAMELOOKUP_TIME
Time consumed by name resolution

CURLINFO_CONNECT_TIME
Time used to establish a connection

CURLINFO_PRETRANSFER_TIME
Time used to prepare the transmission from the established connection

CURLINFO_STARTTRANSFER_TIME
The time used to start the connection.

CURLINFO_REDIRECT_TIME
The time used for redirection before the start of transaction transmission.

CURLINFO_SIZE_UPLOAD
Total uploaded data volume

CURLINFO_SIZE_DOWNLOAD
Total downloaded data volume

CURLINFO_SPEED_DOWNLOAD
Average download speed

CURLINFO_SPEED_UPLOAD
Average upload speed

CURLINFO_HEADER_SIZE
Header Size

CURLINFO_HEADER_OUT
Request string

CURLINFO_REQUEST_SIZE
The size of the problematic HTTP request

CURLINFO_SSL_VERIFYRESULT
Result of SSL certification verification requested by setting CURLOPT_SSL_VERIFYPEER

CURLINFO_CONTENT_LENGTH_DOWNLOAD
Length of the downloaded Content read from Content-Length: field

CURLINFO_CONTENT_LENGTH_UPLOAD
Description of uploaded content size

CURLINFO_CONTENT_TYPE
The "Content-type" value of the downloaded Content. NULL indicates that the server has not sent a valid "Content-Type: header"

The curl_setopt () function sets session parameters for a curl. Curl_setopt_array () function is used to set session parameters for a curl in the form of arrays.

$ Ch = curl_init ();
$ Fp = fopen ("example_homepage.txt", "w ");
Curl_setopt ($ ch, CURLOPT_FILE, $ fp );
$ Options = array (
CURLOPT_URL => 'http: // www.baidu.com /',
CURLOPT_HEADER => false
);
Curl_setopt_array ($ ch, $ options );
Curl_exec ($ ch );
Curl_close ($ ch );
Fclose ($ fp );
?>

Configurable parameters include:

CURLOPT_AUTOREFERER
Automatically set referer information in the header

CURLOPT_BINARYTRANSFER
When CURLOPT_RETURNTRANSFER is enabled, data is returned.

CURLOPT_COOKIESESSION
When curl is enabled, only one session cookie is passed and other cookies are ignored. by default, curl returns all cookies to the server. Session cookie is a cookie used to determine whether a session on the server is valid.

CURLOPT_CRLF
When it is enabled, the Unix line break is converted into a carriage return line break.

CURLOPT_DNS_USE_GLOBAL_CACHE
When enabled, a global DNS cache is enabled. this option is thread-safe and the default value is true.

CURLOPT_FAILONERROR
The HTTP status code is displayed. the default behavior is to ignore the HTTP information whose number is less than or equal to 400.

CURLOPT_FILETIME
When enabled, the system tries to modify the information in the remote document. The result is returned through the CURLINFO_FILETIME option of the curl_getinfo () function.

CURLOPT_FOLLOWLOCATION
When enabled, the "Location:" returned by the server is placed in the header and recursively returned to the server. you can use CURLOPT_MAXREDIRS to limit the number of recursive responses.

CURLOPT_FORBID_REUSE
After the interaction is completed, the connection is forcibly disconnected and cannot be reused.

CURLOPT_FRESH_CONNECT
Force a new connection to replace the connection in the cache.

CURLOPT_FTP_USE_EPRT
TRUE to use EPRT (and LPRT) when doing active FTP downloads. Use FALSE to disable EPRT and LPRT and use PORT only.
Added in PHP 5.0.0.

CURLOPT_FTP_USE_EPSV
TRUE to first try an EPSV command for FTP transfers before reverting back to PASV. Set to FALSE to disable EPSV.

CURLOPT_FTPAPPEND
TRUE to append to the remote file instead of overwriting it.

CURLOPT_FTPASCII
An alias of CURLOPT_TRANSFERTEXT. Use that instead.

CURLOPT_FTPLISTONLY
TRUE to only list the names of an FTP directory.

CURLOPT_HEADER
When enabled, the header file information is output as a data stream.

CURLOPT_HTTPGET
When enabled, the HTTP method is set to GET. because GET is set by default, it is used only when it is modified.

CURLOPT_HTTPPROXYTUNNEL
It is transmitted through the HTTP proxy when it is enabled.

CURLOPT_MUTE
This section describes how to restore the default values of all modified parameters in the curl function.

CURLOPT_NETRC
After the connection is established, access ~ /. The netrc file obtains the user name and password to connect to the remote site.

CURLOPT_NOBODY
When enabled, the HTML body section is not output.

CURLOPT_NOPROGRESS
Disable the curl transfer progress bar when enabling. the default value of this item is true.

CURLOPT_NOSIGNAL
When enabled, ignore all curl signals sent to php. This option is enabled by default during SAPI multi-thread transmission.

CURLOPT_POST
When it is enabled, a conventional POST request is sent. the type is application/x-www-form-urlencoded, just like form submission.

CURLOPT_PUT
When enabled, files can be sent over HTTP. both CURLOPT_INFILE and CURLOPT_INFILESIZE must be set.

CURLOPT_RETURNTRANSFER
The information obtained by curl_exec () is returned in the form of a file stream, rather than directly output.

CURLOPT_SSL_VERIFYPEER
FALSE to stop cURL from verifying the peer's certificate. alternate certificates to verify against can be specified with the CURLOPT_CAINFO option or a certificate directory can be specified with the CURLOPT_CAPATH option. CURLOPT_SSL_VERIFYHOST may also need to be TRUE or FALSE if CURLOPT_SSL_VERIFYPEER is disabled (it defaults to 2 ). TRUE by default as of cURL 7.10. default bundle installed as of cURL 7.10.

CURLOPT_TRANSFERTEXT
TRUE to use ASCII mode for FTP transfers. For LDAP, it retrieves data in plain text instead of HTML. On Windows systems, it will not set STDOUT to binary mode.

CURLOPT_UNRESTRICTED_AUTH
The username and password information is continuously appended to multiple locations in the header generated by CURLOPT_FOLLOWLOCATION, even if the domain name has changed.

CURLOPT_UPLOAD
Enable file transfer

CURLOPT_VERBOSE
When enabled, all information is reported and stored in STDERR or the specified CURLOPT_STDERR.

CURLOPT_BUFFERSIZE
The size of the data read into the cache each time. This value is filled every time.

CURLOPT_CLOSEPOLICY
Either CURLCLOSEPOLICY_LEAST_RECENTLY_USED or CURLCLOSEPOLICY_OLDEST exists, but curl is not supported yet ..

CURLOPT_CONNECTTIMEOUT
The waiting time before the connection is initiated. if it is set to 0, no waiting is performed.

CURLOPT_DNS_CACHE_TIMEOUT
Set the time for saving DNS information in the memory. the default value is 120 seconds.

CURLOPT_FTPSSLAUTH
The FTP authentication method (when is activated): CURLFTPAUTH_SSL (try SSL first), CURLFTPAUTH_TLS (try TLS first), or CURLFTPAUTH_DEFAULT (let cURL decide ).

CURLOPT_HTTP_VERSION
Set the HTTP protocol used by curl, CURL_HTTP_VERSION_NONE (let curl determine by itself), CURL_HTTP_VERSION_1_0 (HTTP/1.0), CURL_HTTP_VERSION_1_1 (HTTP/1.1)

CURLOPT_HTTPAUTH
The HTTP verification method used. optional values include CURLAUTH_BASIC, CURLAUTH_DIGEST, CURLAUTH_GSSNEGOTIATE, CURLAUTH_NTLM, CURLAUTH_ANY, and CURLAUTH_ANYSAFE. multiple values can be separated by the "|" operator, curl allows the server to select the best value. CURLAUTH_ANY is equivalent to CURLAUTH_BASIC | CURLAUTH_DIGEST | digest | CURLAUTH_NTLM, CURLAUTH_ANYSAFE is equivalent to CURLAUTH_DIGEST | digest | CURLAUTH_NTLM

CURLOPT_INFILESIZE
Set the size of the uploaded file

CURLOPT_LOW_SPEED_LIMIT
When the transmission speed is less than CURLOPT_LOW_SPEED_LIMIT, PHP will determine whether to cancel the transmission because it is too slow based on CURLOPT_LOW_SPEED_TIME.

CURLOPT_LOW_SPEED_TIME
The number of seconds the transfer shocould be below CURLOPT_LOW_SPEED_LIMIT for PHP to consider the transfer too slow and abort.
When the transmission speed is less than CURLOPT_LOW_SPEED_LIMIT, PHP will determine whether to cancel the transmission because it is too slow based on CURLOPT_LOW_SPEED_TIME.

CURLOPT_MAXCONNECTS
The maximum number of connections allowed. if the maximum number is exceeded, the CURLOPT_CLOSEPOLICY is used to determine which connections should be stopped.

CURLOPT_MAXREDIRS
Specifies the maximum number of HTTP redirects. this option is used with CURLOPT_FOLLOWLOCATION.

CURLOPT_PORT
An optional parameter used to specify the number of connection ports

CURLOPT_PROXYAUTH
The HTTP authentication method (s) to use for the proxy connection. Use the same bitmasks as described in CURLOPT_HTTPAUTH. For proxy authentication, only CURLAUTH_BASIC and CURLAUTH_NTLM are currently supported.

CURLOPT_PROXYPORT
The port number of the proxy to connect to. This port number can also be set in CURLOPT_PROXY.

CURLOPT_PROXYTYPE
Either CURLPROXY_HTTP (default) or CURLPROXY_SOCKS5.

CURLOPT_RESUME_FROM
Transmit a byte offset when resuming transmission (used for resumable transmission)

CURLOPT_SSL_VERIFYHOST
1 to check the existence of a common name in the SSL peer certificate.
2 to check the existence of a common name and also verify that it matches the hostname provided.

CURLOPT_SSLVERSION
The SSL version (2 or 3) to use. By default PHP will try to determine this itself, although in some cases this must be set manually.

CURLOPT_TIMECONDITION
If it has been edited after a certain time specified by CURLOPT_TIMEVALUE, CURL_TIMECOND_IFMODSINCE is used to return to the page. if it has Not been Modified and CURLOPT_HEADER is true, a header of "304 Not Modified" is returned, if CURLOPT_HEADER is false, use CURL_TIMECOND_ISUNMODSINCE. the default value is CURL_TIMECOND_IFMODSINCE.

CURLOPT_TIMEOUT
Sets the maximum number of seconds that curl can be executed.

CURLOPT_TIMEVALUE
Set a timestamp used by CURLOPT_TIMECONDITION. by default, CURL_TIMECOND_IFMODSINCE is used.

CURLOPT_CAINFO
The name of a file holding one or more certificates to verify the peer with. This only makes sense when used in combination with CURLOPT_SSL_VERIFYPEER.

CURLOPT_CAPATH
A directory that holds multiple CA certificates. Use this option alongside CURLOPT_SSL_VERIFYPEER.

CURLOPT_COOKIE
Set the content in the "Set-Cookie:" section of the HTTP request.

CURLOPT_COOKIEFILE
The name of the file containing the cookie information. the cookie file can be in Netscape format or HTTP header information.

CURLOPT_COOKIEJAR
Name of the file that stores cookie information after the connection is closed

CURLOPT_CUSTOMREQUEST
A custom request method to use instead of "GET" or "HEAD" when doing a HTTP request. this is useful for doing "DELETE" or other, more obscure HTTP requests. valid values are things like "GET", "POST", "CONNECT" and so on; I. e. do not enter a whole HTTP request line here. for instance, entering "GET/index.html HTTP/1.0 \ r \ n" wocould be incorrect.
Note: Don't do this without making sure the server supports the custom request method first.

CURLOPT_EGBSOCKET
Like CURLOPT_RANDOM_FILE, except t a filename to an Entropy Gathering Daemon socket.

CURLOPT_ENCODING
The content in "Accept-Encoding:" in the header. the supported Encoding formats are: "identity", "deflate", and "gzip ". If it is set to an empty string, all encoding formats are supported.

CURLOPT_FTPPORT
The value which will be used to get the IP address to use for the FTP "POST" instruction. the "POST" instruction tells the remote server to connect to our specified IP address. the string may be a plain IP address, a hostname, a network interface name (under Unix), or just a plain '-' to use the systems default IP address.

CURLOPT_INTERFACE
The name used in the external network interface can be an interface name, IP address or host name.

CURLOPT_KRB4LEVEL
KRB4 (Kerberos 4) security level settings can be one of the following values: "clear", "safe", "confidential", "private ". The default value is "private". if it is set to null, KRB4 is disabled. Currently, KRB4 can only be used for FTP transmission.

CURLOPT_POSTFIELDS
The "POST" operation in HTTP. If you want to transfer a file, you need a file name starting @.

CURLOPT_PROXY
Set the HTTP proxy server

CURLOPT_PROXYUSERPWD
The username and password used to connect to the proxy server in the format of [username]: [password.

CURLOPT_RANDOM_FILE
Set the name of the file that stores the random seed used by SSL.

CURLOPT_RANGE
Sets an HTTP Transport range, which can be set as a X-Y, and if there are multiple HTTP transport, separate multiple values, such as: "X-Y, n-M ".

CURLOPT_REFERER
Set the value of "Referer:" in the header.

CURLOPT_SSL_CIPHER_LIST
A list of ciphers to use for SSL. For example, RC4-SHA and TLSv1 are valid cipher lists.

CURLOPT_SSLCERT
Pass a string that contains a PEM certificate.

CURLOPT_SSLCERTPASSWD
Pass a password that contains the password required to use the CURLOPT_SSLCERT certificate.

CURLOPT_SSLCERTTYPE
The format of the certificate. Supported formats are "PEM" (default), "DER", and "ENG ".

CURLOPT_SSLENGINE
The identifier for the crypto engine of the private SSL key specified in CURLOPT_SSLKEY.

CURLOPT_SSLENGINE_DEFAULT
The identifier for the crypto engine used for asypolicric crypto operations.

CURLOPT_SSLKEY
The name of a file containing a private SSL key.

CURLOPT_SSLKEYPASSWD
The secret password needed to use the private SSL key specified in CURLOPT_SSLKEY.
Note: Since this option contains a sensitive password, remember to keep the PHP script it is contained within safe.

CURLOPT_SSLKEYTYPE
The key type of the private SSL key specified in CURLOPT_SSLKEY. Supported key types are "PEM" (default), "DER", and "ENG ".

CURLOPT_URL
You can also set the URL address in the curl_init () function of PHP.

CURLOPT_USERAGENT
The HTTP request contains a string containing the "user-agent" header.

CURLOPT_USERPWD
Pass the username and password required for a connection in the format of [username]: [password].

CURLOPT_HTTP200ALIASES
The setting no longer processes the HTTP 200 response in the form of an error. the format is an array.

CURLOPT_HTTPHEADER
Sets an array of transmitted content in a header.

CURLOPT_POSTQUOTE
An array of FTP commands to execute on the server after the FTP request has been completed Med.

CURLOPT_QUOTE
An array of FTP commands to execute on the server prior to the FTP request.

CURLOPT_FILE
Set the location of the output file. The value is a resource type. the default value is STDOUT (browser ).

CURLOPT_INFILE
The address of the file to be read when uploading the file. The value is a resource type.

CURLOPT_STDERR
Set an error output address. The value is a resource type that replaces the default STDERR.

CURLOPT_WRITEHEADER
Sets the address of the file to which the header is written. The value is a resource type.

CURLOPT_HEADERFUNCTION
Set a callback function. this function has two parameters: the first is the resource handle of curl, and the second is the output header data. The output of header data must depend on this function to return the size of written data.

CURLOPT_PASSWDFUNCTION
Set a callback function with three parameters: the first is the resource handle of curl, the second is a password prompt, and the third parameter is the maximum allowed password length. Returns the password value.

CURLOPT_READFUNCTION
Set a callback function with two parameters: the first is the resource handle of curl and the second is the data read. Data reading must depend on this function. The size of the data to be read, such as 0 or EOF.

CURLOPT_WRITEFUNCTION
Set a callback function with two parameters: the first is the resource handle of curl and the second is the written data. Data writing must depend on this function. Returns the exact size of the written data.

The curl_copy_handle () function is used to copy all content and parameters of a curl connection resource.

$ Ch = curl_init ("http://www.baidu.com /");
$ Another = curl_copy_handle ($ ch );
Curl_exec ($ another );
Curl_close ($ another );
?>

The curl_error () function returns a string containing the current session error message.
The curl_errno () function returns a number that contains the current session error message.

The curl_multi_init () function initializes a curl batch processing handle resource.
The curl_multi_add_handle () function adds a separate curl handle resource to the curl batch processing session. The curl_multi_add_handle () function has two parameters. The first parameter indicates a curl batch processing handle resource, and the second parameter indicates a separate curl handle resource.
The curl_multi_exec () function is used to parse a curl batch processing handle. the curl_multi_exec () function has two parameters. The first parameter indicates a batch processing handle resource, the second parameter is a reference value parameter, indicating the number of individual curl handle resources to be processed.
The curl_multi_remove_handle () function removes a handle resource from the curl batch processing handle. the curl_multi_remove_handle () function has two parameters. The first parameter indicates a curl batch processing handle resource, the second parameter represents a separate curl handle resource.
The curl_multi_close () function is used to close a batch processing handle resource.

$ Response = curl_init ();
$ Ch2 = curl_init ();
Curl_setopt ($ scheme, CURLOPT_URL, "http://www.baidu.com /");
Curl_setopt ($ scheme, CURLOPT_HEADER, 0 );
Curl_setopt ($ ch2, CURLOPT_URL, "http://www.google.com /");
Curl_setopt ($ ch2, CURLOPT_HEADER, 0 );
$ Mh = curl_multi_init ();
Curl_multi_add_handle ($ mh, $ handle );
Curl_multi_add_handle ($ mh, $ ch2 );
Do {
Curl_multi_exec ($ mh, $ flag );
} While ($ flag> 0 );
Curl_multi_remove_handle ($ mh, $ handle );
Curl_multi_remove_handle ($ mh, $ ch2 );
Curl_multi_close ($ mh );
?>

The curl_multi_getcontent () function is used to return the obtained text stream when CURLOPT_RETURNTRANSFER is set.

The curl_multi_info_read () function is used to obtain the transmission information of the currently resolved curl.

Curl_multi_select ()
Get all the sockets associated with the cURL extension, which can then be "selected"

Closing (Client URL Library Function) curl_close-close a curl session curl_copy_handle-copy all the content and parameters of a curl connection resource curl_errno -...

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.