PHP curl_multi_info_read Function
(PHP 5)
curl_multi_info_read — Get information about the current transfers
Description
array curl_multi_info_read ( resource $mh [, int &$msgs_in_queue = NULL ] )
Queries the multi handle to see if there are any messages or information from the individual transfer threads. Messages may include information about errors or just reports about whether a transfer is complete.
Each call to this function returns a new result, and the function can be called repeatedly until there is no more information to return, at which point FALSE
is returned as a signal. The integer returned by msgs_in_queue
indicates the number of messages that remain after this function was called.
Note: The data referenced by the returned resource will not exist after calling curl_multi_remove_handle()
.
Parameters
mh
A cURL multi handle returned by curl_multi_init()
.
msgsinqueue
Number of messages that remain in the queue.
Return Values
Returns an array with information about the transfers on success, or FALSE
on failure.
Contents of the returned array:
Key | Value |
---|---|
msg | The CURLMSG_DONE constant. Other return values are currently not available. |
result | One of the CURLE_* constants. If everything is OK, CURLE_OK will be returned. |
handle | cURL resource type indicating the associated handle. |
Examples
<?php
$urls = array(
"http://www.baidu.com/",
"http://www.google.com.hk/",
"http://www.w3cschool.cc/"
);
$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));
?>
The above example will output something similar to:
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)
Changelog
Version | Description |
---|---|
5.2.0 | msgs_in_queue was added. |