function rolling_curl($urls, $delay) {
    $queue = curl_multi_init();
    $map = array();
 
    foreach ($urls as $url) {
        $ch = curl_init();
 
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_TIMEOUT, 1);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_setopt($ch, CURLOPT_NOSIGNAL, true);
 
        curl_multi_add_handle($queue, $ch);
        $map[(string) $ch] = $url;
    }
 
    $responses = array();
    do {
        while (($code = curl_multi_exec($queue, $active)) == CURLM_CALL_MULTI_PERFORM) ;
 
        if ($code != CURLM_OK) { break; }
 
        // a request was just completed -- find out which one
        while ($done = curl_multi_info_read($queue)) {
 
            // get the info and content returned on the request
            $info = curl_getinfo($done['handle']);
            $error = curl_error($done['handle']);
            $results = callback(curl_multi_getcontent($done['handle']), $delay);
            $responses[$map[(string) $done['handle']]] = compact('info', 'error', 'results');
 
            // remove the curl handle that just completed
            curl_multi_remove_handle($queue, $done['handle']);
            curl_close($done['handle']);
        }
 
        // Block for data in / output; error handling is done by curl_multi_exec
        if ($active > 0) {
            curl_multi_select($queue, 0.5);
        }
 
    } while ($active);
 
    curl_multi_close($queue);
    return $responses;
}也就是第三十行是什么功能?
curl_multi_getcontent($done['handle'])我知道,后面那个参数有什么作用?curl cURL php 并发 curlcURL php 并发 curlcURL并发

解决方案 »

  1.   

    你看看自定义函数 callback 的定义不就知道了吗?
    $delay 是你传入的,并传递给 callback 的,意义当然只有你知道
      

  2.   

    嗯 查看一下 callback 这个函数的代码写的是什么 要是看不懂可以发上来
      

  3.   

    找到了原来是...原来是测试性能的
    function callback($data, $delay) {
        preg_match_all('/<h3>(.+)<\/h3>/iU', $data, $matches);
        usleep($delay);
        return compact('data', 'matches');
    }唉这就是自己看文章不完整引起的
    嗯,谢谢两位版主的提醒~~~