php下目前為目最全的CURL中文說(shuō)明
Jun 13, 2016 pm 12:14 PM
PHP中的CURL函數(shù)庫(kù)(Client URL Library Function)
curl_close — 關(guān)閉一個(gè)curl會(huì)話(huà)
curl_copy_handle — 拷貝一個(gè)curl連接資源的所有內(nèi)容和參數(shù)
curl_errno — 返回一個(gè)包含當(dāng)前會(huì)話(huà)錯(cuò)誤信息的數(shù)字編號(hào)
curl_error — 返回一個(gè)包含當(dāng)前會(huì)話(huà)錯(cuò)誤信息的字符串
curl_exec — 執(zhí)行一個(gè)curl會(huì)話(huà)
curl_getinfo — 獲取一個(gè)curl連接資源句柄的信息
curl_init — 初始化一個(gè)curl會(huì)話(huà)
curl_multi_add_handle — 向curl批處理會(huì)話(huà)中添加單獨(dú)的curl句柄資源
curl_multi_close — 關(guān)閉一個(gè)批處理句柄資源
curl_multi_exec — 解析一個(gè)curl批處理句柄
curl_multi_getcontent — 返回獲取的輸出的文本流
curl_multi_info_read — 獲取當(dāng)前解析的curl的相關(guān)傳輸信息
curl_multi_init — 初始化一個(gè)curl批處理句柄資源
curl_multi_remove_handle — 移除curl批處理句柄資源中的某個(gè)句柄資源
curl_multi_select — Get all the sockets associated with the cURL extension, which can then be "selected"
curl_setopt_array — 以數(shù)組的形式為一個(gè)curl設(shè)置會(huì)話(huà)參數(shù)
curl_setopt — 為一個(gè)curl設(shè)置會(huì)話(huà)參數(shù)
curl_version — 獲取curl相關(guān)的版本信息
curl_init()函數(shù)的作用初始化一個(gè)curl會(huì)話(huà),curl_init()函數(shù)唯一的一個(gè)參數(shù)是可選的,表示一個(gè)url地址。
curl_exec()函數(shù)的作用是執(zhí)行一個(gè)curl會(huì)話(huà),唯一的參數(shù)是curl_init()函數(shù)返回的句柄。
curl_close()函數(shù)的作用是關(guān)閉一個(gè)curl會(huì)話(huà),唯一的參數(shù)是curl_init()函數(shù)返回的句柄。
$ch = curl_init("http://www.baidu.com/");
curl_exec($ch);
curl_close($ch);
?>
curl_version()函數(shù)的作用是獲取curl相關(guān)的版本信息,curl_version()函數(shù)有一個(gè)參數(shù),不清楚是做什么的
print_r(curl_version())
?>
curl_getinfo()函數(shù)的作用是獲取一個(gè)curl連接資源句柄的信息,curl_getinfo()函數(shù)有兩個(gè)參數(shù),第一個(gè)參數(shù)是curl的資源句柄,第二個(gè)參數(shù)是下面一些常量:
$ch = curl_init("http://www.baidu.com/");
print_r(curl_getinfo($ch));
?>
可選的常量包括:
CURLINFO_EFFECTIVE_URL
最后一個(gè)有效的url地址
CURLINFO_HTTP_CODE
最后一個(gè)收到的HTTP代碼
CURLINFO_FILETIME
遠(yuǎn)程獲取文檔的時(shí)間,如果無(wú)法獲取,則返回值為“-1”
CURLINFO_TOTAL_TIME
最后一次傳輸所消耗的時(shí)間
CURLINFO_NAMELOOKUP_TIME
名稱(chēng)解析所消耗的時(shí)間
CURLINFO_CONNECT_TIME
建立連接所消耗的時(shí)間
CURLINFO_PRETRANSFER_TIME
從建立連接到準(zhǔn)備傳輸所使用的時(shí)間
CURLINFO_STARTTRANSFER_TIME
從建立連接到傳輸開(kāi)始所使用的時(shí)間
CURLINFO_REDIRECT_TIME
在事務(wù)傳輸開(kāi)始前重定向所使用的時(shí)間
CURLINFO_SIZE_UPLOAD
上傳數(shù)據(jù)量的總值
CURLINFO_SIZE_DOWNLOAD
下載數(shù)據(jù)量的總值
CURLINFO_SPEED_DOWNLOAD
平均下載速度
CURLINFO_SPEED_UPLOAD
平均上傳速度
CURLINFO_HEADER_SIZE
header部分的大小
CURLINFO_HEADER_OUT
發(fā)送請(qǐng)求的字符串
CURLINFO_REQUEST_SIZE
在HTTP請(qǐng)求中有問(wèn)題的請(qǐng)求的大小
CURLINFO_SSL_VERIFYRESULT
Result of SSL certification verification requested by setting CURLOPT_SSL_VERIFYPEER
CURLINFO_CONTENT_LENGTH_DOWNLOAD
從Content-Length: field中讀取的下載內(nèi)容長(zhǎng)度
CURLINFO_CONTENT_LENGTH_UPLOAD
上傳內(nèi)容大小的說(shuō)明
CURLINFO_CONTENT_TYPE
下載內(nèi)容的“Content-type”值,NULL表示服務(wù)器沒(méi)有發(fā)送有效的“Content-Type: header”
curl_setopt()函數(shù)的作用是為一個(gè)curl設(shè)置會(huì)話(huà)參數(shù)。curl_setopt_array()函數(shù)的作用是以數(shù)組的形式為一個(gè)curl設(shè)置會(huì)話(huà)參數(shù)。
$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);
?>
可設(shè)置的參數(shù)有:
CURLOPT_AUTOREFERER
自動(dòng)設(shè)置header中的referer信息
CURLOPT_BINARYTRANSFER
在啟用CURLOPT_RETURNTRANSFER時(shí)候?qū)@取數(shù)據(jù)返回
CURLOPT_COOKIESESSION
啟用時(shí)curl會(huì)僅僅傳遞一個(gè)session cookie,忽略其他的cookie,默認(rèn)狀況下curl會(huì)將所有的cookie返回給服務(wù)端。session cookie是指那些用來(lái)判斷服務(wù)器端的session是否有效而存在的cookie。
CURLOPT_CRLF
啟用時(shí)將Unix的換行符轉(zhuǎn)換成回車(chē)換行符。
CURLOPT_DNS_USE_GLOBAL_CACHE
啟用時(shí)會(huì)啟用一個(gè)全局的DNS緩存,此項(xiàng)為線(xiàn)程安全的,并且默認(rèn)為true。
CURLOPT_FAILONERROR
顯示HTTP狀態(tài)碼,默認(rèn)行為是忽略編號(hào)小于等于400的HTTP信息
CURLOPT_FILETIME
啟用時(shí)會(huì)嘗試修改遠(yuǎn)程文檔中的信息。結(jié)果信息會(huì)通過(guò)curl_getinfo()函數(shù)的CURLINFO_FILETIME選項(xiàng)返回。
CURLOPT_FOLLOWLOCATION
啟用時(shí)會(huì)將服務(wù)器服務(wù)器返回的“Location:”放在header中遞歸的返回給服務(wù)器,使用CURLOPT_MAXREDIRS可以限定遞歸返回的數(shù)量。
CURLOPT_FORBID_REUSE
在完成交互以后強(qiáng)迫斷開(kāi)連接,不能重用。
CURLOPT_FRESH_CONNECT
強(qiáng)制獲取一個(gè)新的連接,替代緩存中的連接。
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
啟用時(shí)會(huì)將頭文件的信息作為數(shù)據(jù)流輸出。
CURLOPT_HTTPGET
啟用時(shí)會(huì)設(shè)置HTTP的method為GET,因?yàn)镚ET是默認(rèn)是,所以只在被修改的情況下使用。
CURLOPT_HTTPPROXYTUNNEL
啟用時(shí)會(huì)通過(guò)HTTP代理來(lái)傳輸。
CURLOPT_MUTE
講curl函數(shù)中所有修改過(guò)的參數(shù)恢復(fù)默認(rèn)值。
CURLOPT_NETRC
在連接建立以后,訪(fǎng)問(wèn)~/.netrc文件獲取用戶(hù)名和密碼信息連接遠(yuǎn)程站點(diǎn)。
CURLOPT_NOBODY
啟用時(shí)將不對(duì)HTML中的body部分進(jìn)行輸出。
CURLOPT_NOPROGRESS
啟用時(shí)關(guān)閉curl傳輸?shù)倪M(jìn)度條,此項(xiàng)的默認(rèn)設(shè)置為true
CURLOPT_NOSIGNAL
啟用時(shí)忽略所有的curl傳遞給php進(jìn)行的信號(hào)。在SAPI多線(xiàn)程傳輸時(shí)此項(xiàng)被默認(rèn)打開(kāi)。
CURLOPT_POST
啟用時(shí)會(huì)發(fā)送一個(gè)常規(guī)的POST請(qǐng)求,類(lèi)型為:application/x-www-form-urlencoded,就像表單提交的一樣。
CURLOPT_PUT
啟用時(shí)允許HTTP發(fā)送文件,必須同時(shí)設(shè)置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產(chǎn)生的header中的多個(gè)locations中持續(xù)追加用戶(hù)名和密碼信息,即使域名已發(fā)生改變。
CURLOPT_UPLOAD
啟用時(shí)允許文件傳輸
CURLOPT_VERBOSE
啟用時(shí)會(huì)匯報(bào)所有的信息,存放在STDERR或指定的CURLOPT_STDERR中
CURLOPT_BUFFERSIZE
每次獲取的數(shù)據(jù)中讀入緩存的大小,這個(gè)值每次都會(huì)被填滿(mǎn)。
CURLOPT_CLOSEPOLICY
不是CURLCLOSEPOLICY_LEAST_RECENTLY_USED就是CURLCLOSEPOLICY_OLDEST,還存在另外三個(gè),但是curl暫時(shí)還不支持。.
CURLOPT_CONNECTTIMEOUT
在發(fā)起連接前等待的時(shí)間,如果設(shè)置為0,則不等待。
CURLOPT_DNS_CACHE_TIMEOUT
設(shè)置在內(nèi)存中保存DNS信息的時(shí)間,默認(rèn)為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
設(shè)置curl使用的HTTP協(xié)議,CURL_HTTP_VERSION_NONE(讓curl自己判斷),CURL_HTTP_VERSION_1_0(HTTP/1.0),CURL_HTTP_VERSION_1_1(HTTP/1.1)
CURLOPT_HTTPAUTH
使用的HTTP驗(yàn)證方法,可選的值有:CURLAUTH_BASIC,CURLAUTH_DIGEST,CURLAUTH_GSSNEGOTIATE,CURLAUTH_NTLM,CURLAUTH_ANY,CURLAUTH_ANYSAFE,可以使用“|”操作符分隔多個(gè)值,curl讓服務(wù)器選擇一個(gè)支持最好的值,CURLAUTH_ANY等價(jià)于CURLAUTH_BASIC | CURLAUTH_DIGEST | CURLAUTH_GSSNEGOTIATE | CURLAUTH_NTLM,CURLAUTH_ANYSAFE等價(jià)于CURLAUTH_DIGEST | CURLAUTH_GSSNEGOTIATE | CURLAUTH_NTLM
CURLOPT_INFILESIZE
設(shè)定上傳文件的大小
CURLOPT_LOW_SPEED_LIMIT
當(dāng)傳輸速度小于CURLOPT_LOW_SPEED_LIMIT時(shí),PHP會(huì)根據(jù)CURLOPT_LOW_SPEED_TIME來(lái)判斷是否因太慢而取消傳輸。
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.
當(dāng)傳輸速度小于CURLOPT_LOW_SPEED_LIMIT時(shí),PHP會(huì)根據(jù)CURLOPT_LOW_SPEED_TIME來(lái)判斷是否因太慢而取消傳輸。
CURLOPT_MAXCONNECTS
允許的最大連接數(shù)量,超過(guò)是會(huì)通過(guò)CURLOPT_CLOSEPOLICY決定應(yīng)該停止哪些連接
CURLOPT_MAXREDIRS
指定最多的HTTP重定向的數(shù)量,這個(gè)選項(xiàng)是和CURLOPT_FOLLOWLOCATION一起使用的。
CURLOPT_PORT
一個(gè)可選的用來(lái)指定連接端口的量
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
在恢復(fù)傳輸時(shí)傳遞一個(gè)字節(jié)偏移量(用來(lái)斷點(diǎn)續(xù)傳)
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
如果在CURLOPT_TIMEVALUE指定的某個(gè)時(shí)間以后被編輯過(guò),則使用CURL_TIMECOND_IFMODSINCE返回頁(yè)面,如果沒(méi)有被修改過(guò),并且CURLOPT_HEADER為true,則返回一個(gè)"304 Not Modified"的header,CURLOPT_HEADER為false,則使用CURL_TIMECOND_ISUNMODSINCE,默認(rèn)值為CURL_TIMECOND_IFMODSINCE
CURLOPT_TIMEOUT
設(shè)置curl允許執(zhí)行的最長(zhǎng)秒數(shù)
CURLOPT_TIMEVALUE
設(shè)置一個(gè)CURLOPT_TIMECONDITION使用的時(shí)間戳,在默認(rèn)狀態(tài)下使用的是CURL_TIMECOND_IFMODSINCE
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
設(shè)定HTTP請(qǐng)求中“Set-Cookie:”部分的內(nèi)容。
CURLOPT_COOKIEFILE
包含cookie信息的文件名稱(chēng),這個(gè)cookie文件可以是Netscape格式或者HTTP風(fēng)格的header信息。
CURLOPT_COOKIEJAR
連接關(guān)閉以后,存放cookie信息的文件名稱(chēng)
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\r\n" 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
header中“Accept-Encoding: ”部分的內(nèi)容,支持的編碼格式為:"identity","deflate","gzip"。如果設(shè)置為空字符串,則表示支持所有的編碼格式
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
在外部網(wǎng)絡(luò)接口中使用的名稱(chēng),可以是一個(gè)接口名,IP或者主機(jī)名。
CURLOPT_KRB4LEVEL
KRB4(Kerberos 4)安全級(jí)別的設(shè)置,可以是一下幾個(gè)值之一:"clear","safe","confidential","private"。默認(rèn)的值為"private",設(shè)置為null的時(shí)候表示禁用KRB4,現(xiàn)在KRB4安全僅能在FTP傳輸中使用。
CURLOPT_POSTFIELDS
在HTTP中的“POST”操作。如果要傳送一個(gè)文件,需要一個(gè)@開(kāi)頭的文件名
CURLOPT_PROXY
設(shè)置通過(guò)的HTTP代理服務(wù)器
CURLOPT_PROXYUSERPWD
連接到代理服務(wù)器的,格式為“[username]:[password]”的用戶(hù)名和密碼。
CURLOPT_RANDOM_FILE
設(shè)定存放SSL用到的隨機(jī)數(shù)種子的文件名稱(chēng)
CURLOPT_RANGE
設(shè)置HTTP傳輸范圍,可以用“X-Y”的形式設(shè)置一個(gè)傳輸區(qū)間,如果有多個(gè)HTTP傳輸,則使用逗號(hào)分隔多個(gè)值,形如:"X-Y,N-M"。
CURLOPT_REFERER
設(shè)置header中"Referer: " 部分的值。
CURLOPT_SSL_CIPHER_LIST
A list of ciphers to use for SSL. For example, RC4-SHA and TLSv1 are valid cipher lists.
CURLOPT_SSLCERT
傳遞一個(gè)包含PEM格式證書(shū)的字符串。
CURLOPT_SSLCERTPASSWD
傳遞一個(gè)包含使用CURLOPT_SSLCERT證書(shū)必需的密碼。
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
需要獲取的URL地址,也可以在PHP的curl_init()函數(shù)中設(shè)置。
CURLOPT_USERAGENT
在HTTP請(qǐng)求中包含一個(gè)”user-agent”頭的字符串。
CURLOPT_USERPWD
傳遞一個(gè)連接中需要的用戶(hù)名和密碼,格式為:“[username]:[password]”。
CURLOPT_HTTP200ALIASES
設(shè)置不再以error的形式來(lái)處理HTTP 200的響應(yīng),格式為一個(gè)數(shù)組。
CURLOPT_HTTPHEADER
設(shè)置一個(gè)header中傳輸內(nèi)容的數(shù)組。
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
設(shè)置輸出文件的位置,值是一個(gè)資源類(lèi)型,默認(rèn)為STDOUT (瀏覽器)。
CURLOPT_INFILE
在上傳文件的時(shí)候需要讀取的文件地址,值是一個(gè)資源類(lèi)型。
CURLOPT_STDERR
設(shè)置一個(gè)錯(cuò)誤輸出地址,值是一個(gè)資源類(lèi)型,取代默認(rèn)的STDERR。
CURLOPT_WRITEHEADER
設(shè)置header部分內(nèi)容的寫(xiě)入的文件地址,值是一個(gè)資源類(lèi)型。
CURLOPT_HEADERFUNCTION
設(shè)置一個(gè)回調(diào)函數(shù),這個(gè)函數(shù)有兩個(gè)參數(shù),第一個(gè)是curl的資源句柄,第二個(gè)是輸出的header數(shù)據(jù)。header數(shù)據(jù)的輸出必須依賴(lài)這個(gè)函數(shù),返回已寫(xiě)入的數(shù)據(jù)大小。
CURLOPT_PASSWDFUNCTION
設(shè)置一個(gè)回調(diào)函數(shù),有三個(gè)參數(shù),第一個(gè)是curl的資源句柄,第二個(gè)是一個(gè)密碼提示符,第三個(gè)參數(shù)是密碼長(zhǎng)度允許的最大值。返回密碼的值。
CURLOPT_READFUNCTION
設(shè)置一個(gè)回調(diào)函數(shù),有兩個(gè)參數(shù),第一個(gè)是curl的資源句柄,第二個(gè)是讀取到的數(shù)據(jù)。數(shù)據(jù)讀取必須依賴(lài)這個(gè)函數(shù)。返回讀取數(shù)據(jù)的大小,比如0或者EOF。
CURLOPT_WRITEFUNCTION
設(shè)置一個(gè)回調(diào)函數(shù),有兩個(gè)參數(shù),第一個(gè)是curl的資源句柄,第二個(gè)是寫(xiě)入的數(shù)據(jù)。數(shù)據(jù)寫(xiě)入必須依賴(lài)這個(gè)函數(shù)。返回精確的已寫(xiě)入數(shù)據(jù)的大小
curl_copy_handle()函數(shù)的作用是拷貝一個(gè)curl連接資源的所有內(nèi)容和參數(shù)
$ch = curl_init("http://www.baidu.com/");
$another = curl_copy_handle($ch);
curl_exec($another);
curl_close($another);
?>
curl_error()函數(shù)的作用是返回一個(gè)包含當(dāng)前會(huì)話(huà)錯(cuò)誤信息的字符串。
curl_errno()函數(shù)的作用是返回一個(gè)包含當(dāng)前會(huì)話(huà)錯(cuò)誤信息的數(shù)字編號(hào)。
curl_multi_init()函數(shù)的作用是初始化一個(gè)curl批處理句柄資源。
curl_multi_add_handle()函數(shù)的作用是向curl批處理會(huì)話(huà)中添加單獨(dú)的curl句柄資源。curl_multi_add_handle()函數(shù)有兩個(gè)參數(shù),第一個(gè)參數(shù)表示一個(gè)curl批處理句柄資源,第二個(gè)參數(shù)表示一個(gè)單獨(dú)的curl句柄資源。
curl_multi_exec()函數(shù)的作用是解析一個(gè)curl批處理句柄,curl_multi_exec()函數(shù)有兩個(gè)參數(shù),第一個(gè)參數(shù)表示一個(gè)批處理句柄資源,第二個(gè)參數(shù)是一個(gè)引用值的參數(shù),表示剩余需要處理的單個(gè)的curl句柄資源數(shù)量。
curl_multi_remove_handle()函數(shù)表示移除curl批處理句柄資源中的某個(gè)句柄資源,curl_multi_remove_handle()函數(shù)有兩個(gè)參數(shù),第一個(gè)參數(shù)表示一個(gè)curl批處理句柄資源,第二個(gè)參數(shù)表示一個(gè)單獨(dú)的curl句柄資源。
curl_multi_close()函數(shù)的作用是關(guān)閉一個(gè)批處理句柄資源。
$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()函數(shù)的作用是在設(shè)置了CURLOPT_RETURNTRANSFER的情況下,返回獲取的輸出的文本流。
curl_multi_info_read()函數(shù)的作用是獲取當(dāng)前解析的curl的相關(guān)傳輸信息。
curl_multi_select()
Get all the sockets associated with the cURL extension, which can then be "selected"

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

When writing PHP comments, you should clarify the purpose, logic and structure. 1. Each function and class uses DocBlock format to explain the role, parameters and return values; 2. Explain "why" in the key logic rather than just "what was done"; 3. Add a brief description at the top of the file, including functions, dependencies and usage scenarios; 4. Avoid nonsense comments, add only necessary instructions before complex logic, and do not record the modification history. This improves code readability and maintenance efficiency.

Comments are crucial in code because they improve the readability and maintenance of the code, especially in projects like PHP that are multi-collaborative and long-term maintenance. Reasons for writing comments include explaining “why do this” to save debugging time and be friendly to newbies and reduce communication costs. The representation of good comments includes explaining the role of functions or classes to explain complex logic intent marking to-dos or potential problems, and writing API interface documentation annotations. Typical manifestations of bad comments include repeated code content comments that are inconsistent with code and using comments to cover up bad code and retaining old information. Suggestions for writing comments include prioritizing comments "why" keeping comments synced with code Use a unified format to avoid emotional statements and consider optimizing code rather than relying on comments when the code is difficult to understand.

Defining constants in PHP, const is more suitable for constant definitions inside classes, and define() is more flexible and suitable for global or dynamic definitions. 1.const is a language structure, and must be a compile-time constant expression when defined, which is suitable for class or global namespaces; define() is a function, and the value can be the result of runtime calculation. 2.const is affected by the namespace, and the constants defined by define() are visible globally by default. 3. The const structure is clear and the IDE is good, which is suitable for object-oriented design; define() has high flexibility but may have higher maintenance costs. 4. define() supports runtime condition judgment and dynamic definition, but const does not support it. Therefore, class-related constants preferentially use co

PHP comparison operators need to pay attention to type conversion issues. 1. Use == to compare values only, and type conversion will be performed, such as 1=="1" is true; 2. Use === to require the same value as the type, such as 1==="1" is false; 3. Size comparison can be used on values and strings, such as "apple"

There are three common methods for PHP comment code: 1. Use // or # to block one line of code, and it is recommended to use //; 2. Use /.../ to wrap code blocks with multiple lines, which cannot be nested but can be crossed; 3. Combination skills comments such as using /if(){}/ to control logic blocks, or to improve efficiency with editor shortcut keys, you should pay attention to closing symbols and avoid nesting when using them.

When using if/else control structure for conditional judgment in PHP, the following points should be followed: 1. Use if/else when different code blocks need to be executed according to the conditions; 2. Execute if branches if the condition is true, enter else or elseif if they are false; 3. When multi-conditional judgment, elseif should be arranged in logical order, and the range should be placed in front of the front; 4. Avoid too deep nesting, it is recommended to consider switch or reconstruction above three layers; 5. Always use curly braces {} to improve readability; 6. Pay attention to Boolean conversion issues to prevent type misjudgment; 7. Use ternary operators to simplify the code in simple conditions; 8. Merge and repeat judgments to reduce redundancy; 9. Test boundary values to ensure the complete logic. Mastering these techniques can help improve code quality and stability.

PHP string processing requires mastering core functions and scenarios. 1. Use dot numbers or .= for splicing, and recommend arrays for splicing large amounts of splicing; 2. Use strpos() to search, replace str_replace(), pay attention to case sensitivity and regular usage conditions; 3. Use substr() to intercept, and use sprintf() to format; 4. Use htmlspecialchars() to output HTML, and use parameterized query to database operations. Familiar with these function behaviors can deal with most development scenarios.

The "undefinedindex" error appears because you try to access a key that does not exist in the array. To solve this problem, first, you need to confirm whether the array key exists. You can use isset() or array_key_exists() function to check; second, make sure the form data is submitted correctly, including verifying the existence of the request method and field; third, pay attention to the case sensitivity of the key names to avoid spelling errors; finally, when using hyperglobal arrays such as $_SESSION and $_COOKIE, you should also first check whether the key exists to avoid errors.
