curl_multi_info_read

(PHP 5, PHP 7, PHP 8)

curl_multi_info_read獲取當(dāng)前解析的cURL的相關(guān)傳輸信息

說明

curl_multi_info_read(resource $mh, int &$msgs_in_queue = null): array

查詢批處理句柄是否單獨的傳輸線程中有消息或信息返回。消息可能包含諸如從單獨的傳輸線程返回的錯誤碼或者只是傳輸線程有沒有完成之類的報告。

重復(fù)調(diào)用這個函數(shù),它每次都會返回一個新的結(jié)果,直到這時沒有更多信息返回時,false 被當(dāng)作一個信號返回。通過msgs_in_queue返回的整數(shù)指出將會包含當(dāng)這次函數(shù)被調(diào)用后,還剩余的消息數(shù)。

警告

返回的資源指向的數(shù)據(jù)調(diào)用curl_multi_remove_handle()后將不會存在。

參數(shù)

multi_handle

curl_multi_init() 返回的 cURL 多個句柄。

msgs_in_queue

仍在隊列中的消息數(shù)量。

返回值

成功時返回相關(guān)信息的數(shù)組,失敗時返回false。

返回數(shù)組的內(nèi)容
Key: Value:
msg CURLMSG_DONE常量。其他返回值當(dāng)前不可用。
result CURLE_*常量之一。如果一切操作沒有問題,將會返回CURLE_OK常量。
handle cURL資源類型表明它有關(guān)的句柄。

范例

示例 #1 一個curl_multi_info_read()范例

<?php

$urls 
= array(
   
"http://www.cnn.com/",
   
"http://www.bbc.co.uk/",
   
"http://www.yahoo.com/"
);

$mh curl_multi_init();

foreach (
$urls as $i => $url) {
    
$conn[$i] = curl_init($url);
    
curl_setopt($conn[$i], CURLOPT_RETURNTRANSFER1);
    
curl_multi_add_handle($mh$conn[$i]);
}

do {
    
$status curl_multi_exec($mh$active);
    
$info curl_multi_info_read($mh);
    if (
false !== $info) {
        
var_dump($info);
    }
} while (
$status === CURLM_CALL_MULTI_PERFORM || $active);

foreach (
$urls as $i => $url) {
    
$res[$i] = curl_multi_getcontent($conn[$i]);
    
curl_close($conn[$i]);
}

var_dump(curl_multi_info_read($mh));

?>

以上例程的輸出類似于:

array(3) {
  ["msg"]=>
  int(1)
  ["result"]=>
  int(0)
  ["handle"]=>
  resource(5) of type (curl)
}
array(3) {
  ["msg"]=>
  int(1)
  ["result"]=>
  int(0)
  ["handle"]=>
  resource(7) of type (curl)
}
array(3) {
  ["msg"]=>
  int(1)
  ["result"]=>
  int(0)
  ["handle"]=>
  resource(6) of type (curl)
}
bool(false)

更新日志

版本 說明
5.2.0 msgs_in_queue被加入。

參見