CURL function library (ClientURLLibraryFunction) in PHP)

Source: Internet
Author: User
Currently, the most comprehensive CURL Chinese explanation shows that PHP learning should be well mastered. there are many parameters. most of them are useful. I have mastered it and regular expressions, and it must be a collection expert. in PHP, the CURL function library (ClientURLLibraryFunction) curl_close closes a curl session curl_copy_handle and copies a curl to connect to a resource.

At present, the most comprehensive CURL explanation shows that PHP should be well mastered. There are a lot of parameters, most of which are very useful. It must be a collection master if you have mastered it and regular expressions.
CURL Library Function in PHP)
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.php100.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.php100.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.php100.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

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.