Latest web development tutorials

PHP curl_multi_info_read function

PHP curl_multi_info_read function

PHP Calendar Reference Manual PHP cURL Reference Manual

(PHP 5)

curl_multi_info_read - Get current resolution cURL related transfer of information


Explanation

array curl_multi_info_read ( resource $mh [, int &$msgs_in_queue = NULL ] )

Query batch handle is a separate transmission thread news or information return. Message may contain information such as error codes returned from the individual transport thread or just thread has not completed transmission of such reports.

This function is called repeatedly, it returns each time a new result, until then no more information is returned, FALSE is treated as a return signal. Returned pointed out by msgs_in_queue integer will contain when this function is called, but also the remaining number of messages.

Note: The returned resource data pointed to calls curl_multi_remove_handle () will not exist.


parameter

mh

By the curl_multi_init () returns multiple cURL handles.

msgs_in_queue

The number of messages still in the queue.


return value

It returns an array of relevant information on success, FALSE on failure.

Return value (the return of the array contents):

key value
msg CURLMSG_DONE constant. Other return values ​​are currently unavailable.
result CURLE_* constants. If all operation is no problem, it will return CURLE_OK constant.
handle cURL resource types that it related to the 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)

Update Log

version Explanation
5.2.0 msgs_in_queue added.

PHP Calendar Reference Manual PHP cURL Reference Manual