douchang8219 2014-08-26 07:30
浏览 51

Multi_Curl无法正常工作

I've took an example of using multi_curl from php.net and got a problem. Why does this code downloads page less then 30 times (usually from 5 to 20 times)? I've tried to change timeouts, but this does not helps.

$cmh   = curl_multi_init();
$tasks = array();

for ($i = 0; $i < 30; $i++) {

 $ch = curl_init('http://www.bloomberg.com');
 curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
 curl_setopt($ch, CURLOPT_HEADER, 1);

 $tasks[$i] = $ch;

 curl_multi_add_handle($cmh, $ch);
}

$active = null;
$result = array();

do {
 $mrc = curl_multi_exec($cmh, $active);
} while ($mrc == CURLM_CALL_MULTI_PERFORM);

while ($active && ($mrc == CURLM_OK)) {
if (curl_multi_select($cmh) == -1) {
    usleep(100); 
}

do {
    $mrc = curl_multi_exec($cmh, $active);

    $info = curl_multi_info_read($cmh);

    if ($info['msg'] == CURLMSG_DONE) {
        $ch                  = $info['handle'];
        $url                 = array_search($ch, $tasks);
        $result[intval($ch)] = curl_multi_getcontent($ch);

        echo ($result[intval($ch)]) . '<br/>';

        curl_multi_remove_handle($cmh, $ch);
        curl_close($ch);
    }
} while ($mrc == CURLM_CALL_MULTI_PERFORM);

}
curl_multi_close($cmh);
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 微信公众号自制会员卡没有收款渠道啊
    • ¥15 stable diffusion
    • ¥100 Jenkins自动化部署—悬赏100元
    • ¥15 关于#python#的问题:求帮写python代码
    • ¥20 MATLAB画图图形出现上下震荡的线条
    • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
    • ¥15 perl MISA分析p3_in脚本出错
    • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
    • ¥15 ubuntu虚拟机打包apk错误
    • ¥199 rust编程架构设计的方案 有偿