Just to let others who might be struggling to get it to work, curl_multi_info_read() doesn't work in PHP versions before 5.2.0, and instead returns NULL immediately.
PHP - Manual: curl_multi_info_read
2024-12-22
(PHP 5, PHP 7, PHP 8)
curl_multi_info_read — 获取当前解析的cURL的相关传输信息
$mh
, int &$msgs_in_queue
= null
): array查询批处理句柄是否单独的传输线程中有消息或信息返回。消息可能包含诸如从单独的传输线程返回的错误码或者只是传输线程有没有完成之类的报告。
重复调用这个函数,它每次都会返回一个新的结果,直到这时没有更多信息返回时,false
被当作一个信号返回。通过msgs_in_queue
返回的整数指出将会包含当这次函数被调用后,还剩余的消息数。
返回的资源指向的数据调用curl_multi_remove_handle()后将不会存在。
成功时返回相关信息的数组,失败时返回false
。
Key: | Value: |
---|---|
msg |
CURLMSG_DONE 常量。其他返回值当前不可用。 |
result |
CURLE_* 常量之一。如果一切操作没有问题,将会返回CURLE_OK 常量。 |
handle |
cURL资源类型表明它有关的句柄。 |
示例 #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_RETURNTRANSFER, 1);
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 被加入。
|
Just to let others who might be struggling to get it to work, curl_multi_info_read() doesn't work in PHP versions before 5.2.0, and instead returns NULL immediately.
官方地址:https://www.php.net/manual/en/function.curl-multi-info-read.php