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 5, PHP 7, PHP 8)
curl_multi_info_read — Get information about the current transfers
Ask the multi handle if there are any messages or information from the individual transfers. Messages may include information such as an error code from the transfer or just the fact that a transfer is completed.
Repeated calls to this function will return a new result each time, until a false
is returned
as a signal that there is no more to get at this point. The integer pointed to with
queued_messages
will contain the number of remaining messages after this
function was called.
The data the returned resource points to will not survive calling curl_multi_remove_handle().
mh
Мультидескриптор cURL, якого повертає curl_multi_init().
queued_messages
Number of messages that are still in the queue
On success, returns an associative array for the message, false
on failure.
Key: | Value: |
---|---|
msg |
The CURLMSG_DONE constant. Other return values
are currently not available. |
result |
One of the CURLE_* constants. If everything is
OK, the CURLE_OK will be the result. |
handle |
Resource of type curl indicates the handle which it concerns. |
Версія | Опис |
---|---|
8.0.0 |
multi_handle тепер має бути примірником класу
CurlMultiHandle; раніше очікувався
resource.
|
Приклад #1 A curl_multi_info_read() example
<?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);
if ($active) {
curl_multi_select($mh);
}
while (false !== ($info = curl_multi_info_read($mh))) {
var_dump($info);
}
} while ($active && $status == CURLM_OK);
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)
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.