PHP Multi - Curl用户函数一次只处理一个请求.如何让它并行完成


PHP Multi Curl User Function Processing just 1 Request at a Time. How to get it to be done in Parallel?

好的,我有一个PHP multi - curl类,它一直工作到这一行。

while ($info = curl_multi_info_read($this->MH)) 
{
    $handle     = $info['handle'];
    $curlInfo   = curl_getinfo($handle);
    $url        = $curlInfo['url'];
    $content    = curl_multi_getcontent($handle);
    //here is where the bottleneck happens
    $this->data[] = call_user_func($this->curl['CALLBACK'], $content, $url, $handle);
    curl_multi_remove_handle($this->MH, $handle);
    curl_close($handle);
}

我目前将其设置为每次20个请求。当我在call_user_func之前和之后放入时间戳…我得到了一些东西,我得到了正确的个人时间,因为在第一个请求上完成用户函数大约需要0.4秒。问题是,它不能同时处理请求。第二个请求将花费0.4秒来完成,但处理时间为0.8秒。20个请求后,大约需要8秒。

如果你需要更多的信息,请告诉我。不确定提供处理用户函数的脚本会提供什么,因为它不应该阻止脚本并行运行?我遗漏了什么吗?剧本完全是我想要的,它在工作,它只是没有同时做。

尝试使用pthreads(用于线程)

http://php.net/manual/en/book.pthreads.php

或pcntl_fork(用于多进程)

http://php.net/pcntl_fork