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

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

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

警告

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

參數(shù)

multi_handle

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

msgs_in_queue

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

返回值

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

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

范例

示例 #1 一個(gè)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被加入。

參見