是否可以一次对数组的所有成员执行函数



上下文:

$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
}

上面的脚本一个一个。

我担心的是,当单个元素上的一个过程太长时,其余元素必须等待处理才能处理。

是否可以一次对所有数组项目进行

进行一些搜索,我发现滚动卷发https://github.com/joshfraser/rolling-curl

我以示例为例。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();

最新更新