PHP curl_multi_info_read Function

PHP Calendar 参考手册PHP cURL Reference Manual

(PHP 5)

curl_multi_info_read — Get the relevant transfer information of the current cURL


Description

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

Queries whether the batch handle has messages or information returned from individual transfer threads. Messages may contain reports such as error codes returned from individual transfer threads, or simply reports of whether the transfer threads have completed.

Repeatedly calling this function returns a new result each time, until there is no more information to return, at which point FALSE is returned as a signal. The integer returned through msgs_in_queue indicates the number of messages that will remain after this function call.

Note:The data pointed to by the returned resource will not exist after calling curl_multi_remove_handle().


Parameters

mh

The cURL multi handle returned by curl_multi_init().

msgs_in_queue

The number of messages still in the queue.


Return Values

Returns an array of relevant information on success, or FALSE on failure.

Return value content (content of the returned array)

Key Value
msg CURLMSG_DONEA constant. Other return values are currently unavailable.
result CURLE_*One of the constants. If everything operates without problems, it will returnCURLE_OKConstant.
handle A cURL resource type indicating the handle it is related to.

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 output of the above example is 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_queueAdded.

PHP Calendar 参考手册PHP cURL Reference Manual

Other Extensions