Php curl_multi_info_read curl_getinfo。警告:提供的参数不是有效的cURL句柄资源

时间:2012-09-12 12:07:55

标签: php curl warnings handle curl-multi


我的部分代码:

do{
    curl_multi_exec($mh, $running);
    $done = curl_multi_info_read($mh);
    $info = curl_getinfo($done['handle']);
 while($running > 0);

此代码会产生警告Warning: curl_getinfo(): supplied argument is not a valid cURL handle resource,我不明白为什么。当我做var_dump($done['handle']);时,它会返回resource(7) of type (curl)。请帮我找错。

1 个答案:

答案 0 :(得分:0)

要正确使用curl_multi_exec,请使用以下PHP示例:

<?php
// create both cURL resources
$ch1 = curl_init();
$ch2 = curl_init();

// set URL and other appropriate options
curl_setopt($ch1, CURLOPT_URL, "http://lxr.php.net/");
curl_setopt($ch1, CURLOPT_HEADER, 0);
curl_setopt($ch2, CURLOPT_URL, "http://www.php.net/");
curl_setopt($ch2, CURLOPT_HEADER, 0);

//create the multiple cURL handle
$mh = curl_multi_init();

//add the two handles
curl_multi_add_handle($mh,$ch1);
curl_multi_add_handle($mh,$ch2);

$active = null;
//execute the handles
do {
    $mrc = curl_multi_exec($mh, $active);
} while ($mrc == CURLM_CALL_MULTI_PERFORM);

while ($active && $mrc == CURLM_OK) {
    if (curl_multi_select($mh) != -1) {
        do {
            $mrc = curl_multi_exec($mh, $active);
        } while ($mrc == CURLM_CALL_MULTI_PERFORM);
    }
}

//close the handles
curl_multi_remove_handle($mh, $ch1);
curl_multi_remove_handle($mh, $ch2);
curl_multi_close($mh);

?>