PHP curl details

Source: Internet
Author: User
Tags ftp commands http 200 random seed ssl certificate asymmetric encryption

Statement: I have translated several untranslated parts of the original post.

---------------------------------------------------- The post starts -------------------------------------------------------

 

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.

 

 

<? Php <br/> $ CH = curl_init ("http://www.baidu.com/"); <br/> curl_exec ($ ch); <br/> curl_close ($ ch ); <br/>?> 

 

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.

 

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 put 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: eprt (and lprt) is used for FTP download)

False: only port is used for FTP download.

 

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: list the FTP directories.

 

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

Return the information obtained by curl_exec () in the form of a file stream instead of directly outputting it.

 

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: 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

Use the HTTP verification method for the proxy link. Use the same Bit Blocking description in curlopt_httpauth. Currently, only curlauth_basic and curlauth_ntlm are supported for proxy authentication.

 

Curlopt_proxyport

The proxy port to be connected. This port can also be set in curlopt_proxy.

 

Curlopt_proxytype

Curlproxy_http (default) or curlproxy_socks5.

 

Curlopt_resume_from

Transmit a byte offset when Resuming transmission (used for resumable transmission)

 

Curlopt_ssl_verifyhost

1. Check that there is a shared name in the SSL certificate.

2. Check that a shared name exists and verify that it matches the provided host name.

 

 

Curlopt_sslversion

Use the SSL version (2 or 3 ). By default, PHP will try to determine it, although it must be set manually in some cases.

 

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

One file holds one or more certificates for verification. This is only used with curlopt_ssl_verifypeer.

 

Curlopt_capath

A directory has multiple CA certificates. Use this option to use curlopt_ssl_verifypeer at the same time.

 

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

Instead of using "get" or "head ". This is useful when "delete" or other more concealed HTTP requests. Valid values include "get", "Post", and "Connect. That is to say, do not enter the entire HTTP request. For example, input "Get/index.html HTTP/1.0/R/n/R/N" is incorrect.

 

Curlopt_egbsocket 

Like curlopt_random_file, Except t a filename to an entropy gathering daemon socket.

 

Curlopt_encoding

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

 

Curlopt_ftpport

Used to obtain the IP address for FTP using "Post. The "post" Command tells the remote server to connect to the specified IP address. This string can be an IP address, host name, Network Interface Name (UNIX), or just a common '-' to use the default IP address of the system.

 

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 transfer range, which can be set in the form of a "X-Y", if there are multiple HTTP transfers, multiple values are separated by commas, such as: "X-Y, n-M ".

 

Curlopt_referer 

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

 

Curlopt_ssl_cipher_list

The encryption list for SSL. For example, RC4-SHA and tlsv1 are valid encryption 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

Certificate Format. supported formats include "PEM" (default), "Der", and "eng ".

 

Curlopt_sslengine

The identifier for the crypto engine of the private SSL Key specified in curlopt_sslkey.

Specify the encryption engine ID for the SSL private key in curlopt_sslkey.

 

Curlopt_sslengine_default

ID of the encryption engine used for asymmetric encryption.

 

Curlopt_sslkey

File contains an SSL private key name.

 

Curlopt_sslkeypasswd

The password must be specified using the SSL private key in curlopt_sslkey.

Note: Since this option contains a sensitive password, remember to keep the PHP script safe (that is, it cannot be accessed illegally ).

 

Curlopt_sslkeytype

The SSL Private Key type specified in curlopt_sslkey. Supported types include "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 "User-Agent" header string.

 

Curlopt_userpwd

Pass the username and password required for a connection. The format is "[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.

 

<? Php <br/> $ CH = curl_init ("http://www.baidu.com/"); <br/> $ another = curl_copy_handle ($ ch); <br/> curl_exec ($ another ); <br/> curl_close ($ another); <br/>?> <Br/> curl_exec ($ another); <br/> curl_close ($ another); <br/>?> 

 

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.

 

 

<? Php <br/> $ response = curl_init (); <br/> $ CH2 = curl_init (); <br/> curl_setopt ($ response, curlopt_url, "http://www.baidu.com /"); <br/> curl_setopt ($ scheme, curlopt_header, 0); <br/> curl_setopt ($ CH2, curlopt_url, "http://www.google.com/"); <br/> curl_setopt ($ CH2, curlopt_header, 0); <br/> $ MH = curl_multi_init (); <br/> curl_multi_add_handle ($ MH, $ handle); <br/> curl_multi_add_handle ($ MH, $ CH2); <br/> do {<br/> curl_multi_exec ($ MH, $ flag); <br/>}while ($ flag> 0); <br/> curl_multi_remove_handle ($ MH, $ handle ); <br/> curl_multi_remove_handle ($ MH, $ CH2); <br/> curl_multi_close ($ MH); <br/>?> 

 

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"

 

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.