English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Basic PHP Tutorial

Advanced PHP Tutorial

PHP & MySQL

PHP Reference Manual

Usage and example of PHP curl_multi_info_read() function

PHP CURL Reference Manual

(PHP 5)

curl_multi_info_read — Get the relevant transmission information of the current parsed CURL

Syntax

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

Query whether there are messages or information returned in the separate transmission thread. The message may contain errors returned from the separate transmission thread or simply a report on whether the transmission thread has completed.

Repeatedly calling this function will return 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 by msgs_in_queue indicates the number of messages that will remain when this function is called.

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

parameter

mh

The CURL multiple handles returned by curl_multi_init().

msgs_in_queue

The number of messages still in the queue.

Return value

Returns an array of related information when successful, FALSE when failed.

Return value content (content of the returned array) :

KeyValue
msgCURLMSG_DONEConstant. Other return values are currently not available.
resultCURLE_*One of the constants. It will return if all operations are successful.CURLE_OKConstant.
handleThe CURL resource type indicates the related handle.

Online Example

<?php
$urls = array(
   "http://www.baidu.com/",
   "http://www.google.com.hk/",
   "http://www.oldtoolbag.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));
?>

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)

Update Log

VersionDescription
5.2.0msgs_in_queuehas been added.

PHP CURL Reference Manual