背景:
$a = array('1','2','3');
foreach ($a as $item){
  //rest of code
  //example file_get_contents(url);
  //the script waits for it to be completed before going to the next
}上面的脚本是一个接一个的。
我担心的是,当单个元素上的进程花费太长时间时,剩下的元素必须等待处理。
是否有可能同时对所有数组项进行处理?
发布于 2017-05-06 19:17:39
做些搜索我发现滚动卷曲https://github.com/joshfraser/rolling-curl
我拿了包含的example.php,我把它变短了一点
require("RollingCurl.php");
$urls = array(); // regular array, or from csv or from Database...
function request_callback($response, $info) {
    // parse the page title out of the returned HTML
    if (preg_match("~<title>(.*?)</title>~i", $response, $out)) {
        $title = $out[1];
    }
    echo "<b>$title</b>";
    print_r($info);
    echo "<hr>";
}
$rc = new RollingCurl("request_callback");
$rc->window_size = 20;
foreach ($urls as $url) {
    $request = new RollingCurlRequest($url);
    $rc->add($request);
}
$rc->execute();https://stackoverflow.com/questions/43750444
复制相似问题