使用curl_multi_*
,我想每个 x 请求执行一段代码,有什么办法吗?
我想出的唯一方法是检查$still_running
变量 from curl_multi_exec
,不幸的是,它不起作用(它不一致,有时它从 7 跳到 1 而没有经过 6、5 等。)
这是我想出的代码(它并不总是有效,正如我所说$still_running
的不一致):
$still_running = null;
$callbackExecuted = 1;//Counts how many times callback function was executed.
//execute the handles
do
{
//Execute callback every 5 requests
if ($numberOfRequests - $still_running === 5 * $callbackExecuted)
{
callback();
$callbackExecuted++;
}
curl_multi_exec($mh, $still_running);
} while ($still_running > 0);