Home  >  Article  >  Backend Development  >  PHP CURL CURLOPT parameter description (curl_setopt)

PHP CURL CURLOPT parameter description (curl_setopt)

高洛峰
高洛峰Original
2016-12-23 15:07:281527browse

CURLOPT_RETURNTRANSFER option:

curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);

If successful, only the result will be returned and nothing will be output automatically.

Return FALSE if failed

curl_setopt($ch, CURLOPT_RETURNTRANSFER,0); Or do not use this option:

Only return TRUE if successful and automatically output the returned content.

Returns FALSE if failed

Some parameters of the CURL method curl_setopt() function in PHP .

bool curl_setopt (int ch, string option, mixed value)
curl_setopt() function will set options for a CURL session. The option parameter is the setting you want, and value is the value given by this option.


The values ​​of the following options will be used as long integers (specified in the option parameter): CURLOPT_INFILESIZE: When you upload a file to the remote site, this option tells PHP the size of the file you uploaded.
• CURLOPT_VERBOSE : If you want CURL to report every unexpected event, set this option to a non-zero value.
• CURLOPT_HEADER : If you want to include a header in the output, set this option to a non-zero value.
• CURLOPT_NOPROGRESS: If you don't want PHP to display a progress bar for CURL transfers, set this option to a non-zero value. Note: PHP automatically sets this option to a non-zero value, you should only change this option for debugging purposes.
• CURLOPT_NOBODY : If you don’t want to include the body part in the output, set this option to a non-zero value.
• CURLOPT_FAILONERROR: If you want PHP not to display when an error occurs (HTTP code return greater than or equal to 300), set this option to a non-zero value. The default behavior is to return a normal page and ignore the code.
• CURLOPT_UPLOAD: If you want PHP to prepare for uploading, set this option to a non-zero value.
• CURLOPT_POST : If you want PHP to do a regular HTTP POST, set this option to a non-zero value. This POST is of the ordinary application/x-www-from-urlencoded type, mostly used by HTML forms.
• CURLOPT_FTPLISTONLY: Set this option to a non-zero value and PHP will list the directory names of FTP.
• CURLOPT_FTPAPPEND : Set this option to a non-zero value and PHP will apply the remote file instead of overwriting it.
• CURLOPT_NETRC : Set this option to a non-zero value and PHP will look in your ~./netrc file for the username and password of the remote site you want to connect to.
• CURLOPT_FOLLOWLOCATION : Set this option to a non-zero header (like "Location: "), and the server will send it as part of the HTTP header (note that this is recursive, PHP will send a header like "Location: ") ).
• CURLOPT_PUT : Set this option to a non-zero value to upload a file using HTTP. To upload this file, the CURLOPT_INFILE and CURLOPT_INFILESIZE options must be set.
• CURLOPT_MUTE: Set this option to a non-zero value, and PHP will be completely silent for the CURL function.
• CURLOPT_TIMEOUT: Set a long integer as the maximum number of seconds.
• CURLOPT_LOW_SPEED_LIMIT: Set a long integer to control how many bytes are transmitted.
• CURLOPT_LOW_SPEED_TIME: Set a long integer to control how many seconds to transmit the number of bytes specified by CURLOPT_LOW_SPEED_LIMIT.
• CURLOPT_RESUME_FROM: Pass a long integer parameter containing the byte offset address (the start form you want to transfer to).
• CURLOPT_SSLVERSION: Pass a long parameter containing the SSL version. By default PHP will do its own hard work, in more security you have to set it manually.
• CURLOPT_TIMECONDITION: Pass a long parameter to specify how to handle the CURLOPT_TIMEVALUE parameter. You can set this parameter to TIMECOND_IFMODSINCE or TIMECOND_ISUNMODSINCE. This is only for HTTP.
• CURLOPT_TIMEVALUE: Pass a number of seconds from 1970-1-1 to now. This time will be used as the specified value by the CURLOPT_TIMEVALUE option, or by the default TIMECOND_IFMODSINCE.

The values ​​of the following options will be treated as strings:
• CURLOPT_URL: This is the URL address you want to retrieve using PHP. You can also set this option during initialization with the curl_init() function.
• CURLOPT_USERPWD: Pass a string in the form of [username]:[password] and use PHP to connect.
• CURLOPT_PROXYUSERPWD: Pass a string in the format [username]:[password] to connect to the HTTP proxy.
• CURLOPT_RANGE : Pass a range you want to specify. It should be in "X-Y" format, with X or Y being excluded. HTTP transfers also support several intervals, separated by commas (X-Y,N-M).
• CURLOPT_POSTFIELDS : Pass a string containing all the data as an HTTP "POST" operation.
• CURLOPT_REFERER: A string containing a "referer" header in the HTTP request.
• CURLOPT_USERAGENT: A string containing a "user-agent" header in the HTTP request.
• CURLOPT_FTPPORT: Pass an IP address containing the IP address used by the ftp "POST" command. This POST command tells the remote server to connect to the IP address we specified. This string can be an IP address, a host name, a network interface name (under UNIX), or '-' (use the system default IP address).
• CURLOPT_COOKIE: Pass a header connection containing an HTTP cookie.
• CURLOPT_SSLCERT : Pass a string containing the certificate in PEM format.
• CURLOPT_SSLCERTPASSWD: Pass a password containing the necessary password to use the CURLOPT_SSLCERT certificate.
• CURLOPT_COOKIEFILE: Pass a string containing the name of the file containing cookie data. This cookie file can be in Netscape format, or it can be a stack of HTTP-style headers stored in the file.
• CURLOPT_CUSTOMREQUEST: When making an HTTP request, pass a character to be used by GET or HEAD. Pass a string to be used instead of GET or HEAD when doing an HTTP request. This is useful for doing or another, more obscure, HTTP request. Note: Make sure your server supports Order not to do it yet. The following options require a file description (obtained by using the fopen() function):
• CURLOPT_FILE: This file will be the output file you place the transfer, the default is STDOUT.
• CURLOPT_INFILE: This file will be the input file you transfer.
• CURLOPT_WRITEHEADER: This file contains the header part of your output.
• CURLOPT_STDERR : This file has errors written instead of stderr. Examples used to obtain pages that require login. The current method is to log in once every time. People who need it will make improvements.

Example 1:

$cookie_jar = tempnam('./tmp','cookie');
$ch = curl_init(); curl_setopt($ch,CURLOPT_URL, 'http://******');
curl_setopt($ch, CURLOPT_POST, 1);
$request = 'email_address=&password=&action=';
curl_setopt($ch, CURLOPT_POSTFIELDS, $request); //把返回来的cookie信息保存在$cookie_jar文件中
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_jar); //设定返回的数据是否自动显示
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //设定是否显示头信息
curl_setopt($ch, CURLOPT_HEADER, false); //设定是否输出页面内容
curl_setopt($ch, CURLOPT_NOBODY, false);
curl_exec($ch);
curl_close($ch); //get data after login

Example 2:

$ch2 = curl_init();
curl_setopt($ch2, CURLOPT_URL, 'http://*****');
curl_setopt($ch2, CURLOPT_HEADER, false);
curl_setopt($ch2, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch2, CURLOPT_COOKIEFILE, $cookie_jar);
$orders = curl_exec($ch2);
echo '';
echo strip_tags($orders);
echo '';
curl_close($ch2); 实践证明很稳定:)

Example 3:

set_time_limit(0);
function _rand() {
$length=26;
$chars = "0123456789abcdefghijklmnopqrstuvwxyz";
$max = strlen($chars) - 1;
mt_srand((double)microtime() * 1000000);
$string = '';
for($i = 0; $i < $length; $i++) {
$string .= $chars[mt_rand(0, $max)];
}
return $string;
}
$HTTP_SESSION=_rand();
echo $HTTP_SESSION;
$HTTP_Server="www.baidu.com";
$HTTP_URL="/";
$ch = curl_init();
curl_setopt ($ch,CURLOPT_URL,"http://".$HTTP_Server.$HTTP_URL);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch,CURLOPT_USERAGENT,"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)");
//curl_setopt($ch,CURLOPT_COOKIE,$HTTP_SESSION);
$res = curl_exec($ch);
curl_close ($ch);
print_r($res);

Brush Forum code:
1. Cookie capture program:

$URL="http://www.yoururl.com/bbs/login.asp?action=chk";
//填入论坛的登陆页面地址
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$URL);
curl_setopt($ch,CURLOPT_REFERER,"http://www.hxfoods.com/bbs/login.asp");
//设置,访问页面的来源地址
curl_setopt($ch,CURLOPT_POST,1);
curl_setopt($ch,CURLOPT_POSTFIELDS,&#39;username=→→敢死队→&password=168168&#39;);
//分析登陆页面,把用户名,密码分别对应起来
curl_setopt ($ch, CURLOPT_HEADER,true);
//使能显示http头,
curl_exec($ch);
if (curl_errno($ch))
{
print curl_error($ch);
}
else
{
curl_close($ch);
}

2. Clean the floor:

set_time_limit(0);
//设置程序执行时间无限制
$i=10000;
//耍10000次
for($j=0;$j<$i;$j++)
{
$URL="http://www.yoururl.com/bbs/savepost.asp";
//这个地址是回复表单里面action的url地址
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$URL);
curl_setopt($ch,CURLOPT_REFERER,"http://www.hxfoods.com/bbs/dispbbs.asp?boardid=14&replyid=672709&id=127437&page=1&skin=0&Star=53");
//设置来源地址,如果不设置,论坛服务器有可能有验证不允许回复
curl_setopt($ch,CURLOPT_COOKIESESSION,true);
//能保存cookie
curl_setopt($ch,CURLOPT_COOKIE,"DvForum=userid=24122&usercookies=0&userhidden=2&password=w0reu3g775VrY745&userclass=%96%7C&username=%A1%FA%A1%FA%B8%D2%CB%C0%B6%D3%A1%FA&StatUserID=2194783945 ");
//这儿就是设置cookie了
curl_setopt($ch,CURLOPT_POST,1);
curl_setopt($ch,CURLOPT_NOBODY,1);
//不显示内容,因为有很多论坛回复后要自动跳转。
curl_setopt($ch,CURLOPT_POSTFIELDS,&#39;Body=gfdfgdfgasdfgdfgdfgdfg& followup=672709&RootID=127437&star=58&TotalUseTable=Dv_bbs3& amp;UserName=→→敢死队→&signflag=1&total=65535&#39;);
//把你分析的回复表单的参数分别赋值
curl_setopt ($ch, CURLOPT_HEADER,true);
curl_exec($ch);
if (curl_errno($ch))
{
print curl_error($ch);
}
else
{
curl_close($ch);
}
}

curl_close — close a curl session
curl_copy_handle — copy all content and parameters of a curl connection resource
curl_errno — return an error message containing the current session error The numeric number of the message
curl_error — Returns a string containing error information for the current session
curl_exec — Execute a curl session
curl_getinfo — Get information about a curl connection resource handle
curl_init — Initialize a curl session
curl_multi_add_handle — Batch sessions to curl Add a separate curl handle resource
curl_multi_close — Close a batch handle resource
curl_multi_exec — Parse a curl batch handle
curl_multi_getcontent — Return the text stream of the obtained output
curl_multi_info_read — Get the relevant transmission information of the currently parsed curl
curl_multi_init — Initialize a curl batch handle resource
curl_multi_remove_handle — Remove a handle resource in the curl batch handle resource
curl_multi_select — Get all the sockets associated with the cURL extension, which can then be "selected"
curl_setopt_array — In the form of an array Set session parameters for a curl
curl_setopt — Set session parameters for a curl
curl_version — Get curl-related version information
The role of the curl_init() function is to initialize a curl session. The only parameter of the curl_init() function is optional, indicating A url address.
The curl_exec() function is used to execute a curl session. The only parameter is the handle returned by the curl_init() function.
The curl_close() function 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);
curl_version() function is to obtain curl-related version information. The curl_version() function has a parameter. I don’t know what it does.

print_r(curl_version())
curl_getinfo() function is to obtain information about a curl connection resource handle. The curl_getinfo() function has two parameters. The first The first parameter is the resource handle of curl, and 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
The last valid url address
CURLINFO_HTTP_CODE
Finally A received HTTP code
CURLINFO_FILETIME
The time to retrieve the document remotely. If it cannot be obtained, the return value is "-1"
CURLINFO_TOTAL_TIME
The time consumed by the last transmission
CURLINFO_NAMELOOKUP_TIME
The time consumed by name resolution
CURLINFO_CONNECT_TIME
Establishment The time consumed by the connection
CURLINFO_PRETRANSFER_TIME
The time it takes from establishing the connection to preparing the transfer
CURLINFO_STARTTRANSFER_TIME
The time it takes from establishing the connection to the start of the transfer
CURLINFO_REDIRECT_TIME
The time it takes to redirect before the transaction transfer starts
CURLINFO_SIZE_UPLOAD
Uploading data Total value of amount
CURLINFO_SIZE_DOWNLOAD
Total value of downloaded data amount
CURLINFO_SPEED_DOWNLOAD
Average download speed
CURLINFO_SPEED_UPLOAD
Average upload speed
CURLINFO_HEADER_SIZE
Size of header section
CURLINFO_HEADER_OUT
Send request The string
CURLINFO_REQUEST_SIZE
is problematic in the HTTP request Requested size
CURLINFO_SSL_VERIFYRESULT
Result of SSL certification verification requested by setting CURLOPT_SSL_VERIFYPEER
CURLINFO_CONTENT_LENGTH_DOWNLOAD
Download content length read from Content-Length: field
CURLINFO_CONTENT_LENGTH_UPLOAD
Description of upload content size
CURLINFO_CONTENT_TYPE

"Content-type of download content " value, NULL means that the server did not send a valid "Content-Type: header"

The function of curl_setopt() function is to set session parameters for a curl. The curl_setopt_array() function is used to set session parameters for a curl in the form of an array.

$ch = curl_init();
$fp = fopen("example_homepage.txt", "w");
curl_setopt($ch, CURLOPT_FILE, $fp);
$options = array(
CURLOPT_URL => &#39;http://www.baidu.com/&#39;,
CURLOPT_HEADER => false
);
curl_setopt_array($ch, $options);
curl_exec($ch);
curl_close($ch);
fclose($fp);

可设置的参数有:
CURLOPT_AUTOREFERER
自动设置header中的referer信息
CURLOPT_BINARYTRANSFER
在启用CURLOPT_RETURNTRANSFER时候将获取数据返回
CURLOPT_COOKIESESSION
启用时curl会仅仅传递一个session cookie,忽略其他的cookie,默认状况下curl会将所有的cookie返回给服务端。session cookie是指那些用来判断服务器端的session是否有效而存在的cookie。
CURLOPT_CRLF
启用时将Unix的换行符转换成回车换行符。
CURLOPT_DNS_USE_GLOBAL_CACHE
启用时会启用一个全局的DNS缓存,此项为线程安全的,并且默认为true。
CURLOPT_FAILONERROR
显示HTTP状态码,默认行为是忽略编号小于等于400的HTTP信息
CURLOPT_FILETIME
启用时会尝试修改远程文档中的信息。结果信息会通过curl_getinfo()函数的CURLINFO_FILETIME选项返回。
CURLOPT_FOLLOWLOCATION
启用时会将服务器服务器返回的“Location:”放在header中递归的返回给服务器,使用CURLOPT_MAXREDIRS可以限定递归返回的数量。
CURLOPT_FORBID_REUSE
在完成交互以后强迫断开连接,不能重用。
CURLOPT_FRESH_CONNECT
强制获取一个新的连接,替代缓存中的连接。
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
启用时会将头文件的信息作为数据流输出。
CURLOPT_HTTPGET
启用时会设置HTTP的method为GET,因为GET是默认是,所以只在被修改的情况下使用。
CURLOPT_HTTPPROXYTUNNEL
启用时会通过HTTP代理来传输。
CURLOPT_MUTE
讲curl函数中所有修改过的参数恢复默认值。
CURLOPT_NETRC
在连接建立以后,访问~/.netrc文件获取用户名和密码信息连接远程站点。
CURLOPT_NOBODY
启用时将不对HTML中的body部分进行输出。
CURLOPT_NOPROGRESS
启用时关闭curl传输的进度条,此项的默认设置为true
CURLOPT_NOSIGNAL
启用时忽略所有的curl传递给php进行的信号。在SAPI多线程传输时此项被默认打开。
CURLOPT_POST
启用时会发送一个常规的POST请求,类型为:application/x-www-form-urlencoded,就像表单提交的一样。
CURLOPT_PUT
启用时允许HTTP发送文件,必须同时设置CURLOPT_INFILE和CURLOPT_INFILESIZE
CURLOPT_RETURNTRANSFER
讲curl_exec()获取的信息以文件流的形式返回,而不是直接输出。
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
在使用CURLOPT_FOLLOWLOCATION产生的header中的多个locations中持续追加用户名和密码信息,即使域名已发生改变。
CURLOPT_UPLOAD
启用时允许文件传输
CURLOPT_VERBOSE
启用时会汇报所有的信息,存放在STDERR或指定的CURLOPT_STDERR中
CURLOPT_BUFFERSIZE
每次获取的数据中读入缓存的大小,这个值每次都会被填满。
CURLOPT_CLOSEPOLICY
不是CURLCLOSEPOLICY_LEAST_RECENTLY_USED就是CURLCLOSEPOLICY_OLDEST,还存在另外三个,但是curl暂时还不支持。.
CURLOPT_CONNECTTIMEOUT
在发起连接前等待的时间,如果设置为0,则不等待。
CURLOPT_DNS_CACHE_TIMEOUT
设置在内存中保存DNS信息的时间,默认为120秒。
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
设置curl使用的HTTP协议,CURL_HTTP_VERSION_NONE(让curl自己判断),CURL_HTTP_VERSION_1_0(HTTP/1.0),CURL_HTTP_VERSION_1_1(HTTP/1.1)

CURLOPT_HTTPAUTH

The HTTP verification method used, the optional values ​​are: CURLAUTH_BASIC, CURLAUTH_DIGEST, CURLAUTH_GSSNEGOTIATE, CURLAUTH_NTLM, CURLAUTH_ANY, CURLAUTH_ANYSAFE. You can use the "|" operator to separate multiple values, and curl lets the server choose the one with the best support, CURLAUTH_ANY, etc. Equivalent to CURLAUTH_BASIC | CURLAUTH_DIGEST | CURLAUTH_GSSNEGOTIATE | CURLAUTH_NTLM, CURLAUTH_ANYSAFE is equivalent to CURLAUTH_DIGEST | CURLAUTH_GSSNEGOTIATE | CURLAUTH_NTLM
CURLOPT_INFILESIZE

Set the size of uploaded files

CURLOPT_LOW_SPEED_LIMIT
When the transmission speed is less than CURLOPT_LOW_SPEED_LIMIT, PHP will use CURLOPT_LOW_SPEED_TIME to determine whether to cancel the transmission because it is too slow.
CURLOPT_LOW_SPEED_TIME
The number of seconds the transfer should be below CURLOPT_LOW_SPEED_LIMIT for PHP to consider the transfer too slow and abort.
CURLOPT_MAXCONNECTS
The maximum number of connections allowed. If exceeded, CURLOPT_CLOSEPOLICY will be used to determine which connections should be stopped.
CURLOPT_MAXREDIRS
Specify the maximum number of HTTP redirects. This option is used together with CURLOPT_FOLLOWLOCATION.
CURLOPT_PORT
An optional quantity used to specify the connection port
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
CURLOPT_PROXYPORT
The port number of the proxy to connect to. (Used to resume downloading from breakpoints)
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 edited after a certain time specified by CURLOPT_TIMEVALUE, use CURL_TIMECOND_IFMODSINCE to return If the page has not been modified and CURLOPT_HEADER is true, a "304 Not Modified" header will be returned. If CURLOPT_HEADER is false, CURL_TIMECOND_ISUNMODSINCE will be used. The default value is CURL_TIMECOND_IFMODSINCE
CURLOPT_TIMEOUT
Set the maximum number of seconds curl is allowed to execute
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 of the "Set-Cookie:" part of the HTTP request.
CURLOPT_COOKIEFILE
The name of the file containing cookie information. This cookie file can be Netscape format or HTTP style header information.
CURLOPT_COOKIEJAR
The 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.0rnrn" would 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 a filename to an Entropy Gathering Daemon socket.
CURLOPT_ENCODING
"Accept-Encoding: " in header For some content, the supported encoding formats are: "identity", "deflate", "gzip". If set to an empty string, it means that 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
Use in external network interface The name can be an interface name, IP or host name.
CURLOPT_KRB4LEVEL
KRB4 (Kerberos 4) security level setting can be one of the following values: "clear", "safe", "confidential", "private". The default value is "private". When set to null, it means KRB4 is disabled. Now KRB4 security can only be used in FTP transmission.
CURLOPT_POSTFIELDS
The "POST" operation in HTTP. If you want to transfer a file, you need a file name starting with @
CURLOPT_PROXY
Set the HTTP proxy server
CURLOPT_PROXYUSERPWD
to connect to the proxy server, the user name and password in the format of "[username]:[password]".
CURLOPT_RANDOM_FILE
Set the file name to store the random number seed used by SSL
CURLOPT_RANGE
To set the HTTP transmission range, you can set a transmission range in the form of "X-Y". If there are multiple HTTP transmissions, use commas to separate multiple values, such as: "X-Y,N-M".
CURLOPT_REFERER
Set the value of the "Referer: " part 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 containing the certificate in PEM format.
CURLOPT_SSLCERTPASSWD
Pass a pass containing 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 asymmetric 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
The URL address to be obtained can also be set in the curl_init() function of PHP.
CURLOPT_USERAGENT
Contains a "user-agent" header string in the HTTP request.
CURLOPT_USERPWD
Pass the username and password required for a connection in the format: "[username]:[password]".
CURLOPT_HTTP200ALIASES
The setting no longer handles HTTP 200 responses in the form of error, and the format is an array.
CURLOPT_HTTPHEADER
Set an array of transmission content in the header.
CURLOPT_POSTQUOTE
An array of FTP commands to execute on the server after the FTP request has been performed.
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, value Is a resource type, defaults to STDOUT (browser).
CURLOPT_INFILE
The file address that needs to be read when uploading files. The value is a resource type.
CURLOPT_STDERR
Set an error output address, the value is a resource type, replacing the default STDERR.
CURLOPT_WRITEHEADER
Set the file address where the header part 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 rely on this function, which returns the size of the written data.
CURLOPT_PASSWDFUNCTION
Set a callback function with three parameters. The first is the curl resource handle, the second is a password prompt, and the third parameter is the maximum allowed password length. Returns the value of the password.
CURLOPT_READFUNCTION
Set a callback function with two parameters. The first is the resource handle of curl, and the second is the read data. Data reading must rely on this function. Returns the size of the read data, 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 rely on this function. Return the exact size of the written data

curl_copy_handle() function is to copy all the contents 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);
curl_error() function is to return a string containing error information of the current session. The
curl_errno() function is to return a numeric number containing the error information of the current session.
The curl_multi_init() function is used to initialize a curl batch handle resource.
The curl_multi_add_handle() function is used to add individual curl handle resources to the curl batch session. The curl_multi_add_handle() function has two parameters. The first parameter represents a curl batch handle resource, and the second parameter represents a separate curl handle resource.
The function of curl_multi_exec() is to parse a curl batch handle. The curl_multi_exec() function has two parameters. The first parameter represents a batch handle resource, and the second parameter is a reference value parameter, indicating that the remaining needs to be processed. The number of individual curl handle resources.
The curl_multi_remove_handle() function represents the removal of a handle resource in the curl batch handle resource. The curl_multi_remove_handle() function has two parameters. The first parameter represents a curl batch handle resource, and the second parameter represents a separate curl. Handle resource.
The curl_multi_close() function is used to close a batch handle resource.

$ch1 = curl_init();
$ch2 = curl_init();
curl_setopt($ch1, CURLOPT_URL, "http://www.baidu.com/");
curl_setopt($ch1, 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,$ch1);
curl_multi_add_handle($mh,$ch2);
do {
curl_multi_exec($mh,$flag);
} while ($flag > 0);
curl_multi_remove_handle($mh,$ch1);
curl_multi_remove_handle($mh, $ch2);
curl_multi_close($mh);
curl_multi_getcontent() function is to return the obtained output text stream when CURLOPT_RETURNTRANSFER is set.
The curl_multi_info_read() function is used to obtain the relevant transmission information of the currently parsed curl.
curl_multi_select()
Get all the sockets associated with the cURL extension, which can then be "selected"

For more PHP CURL CURLOPT parameter description (curl_setopt) related articles, please pay attention to the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn