简体   繁体   中英

Sometimes curl_multi_exec repeat requests

I'm doing some requests with curl_multi_exec. My code looks like this:

$rMultiHandler = curl_multi_init();

//next lines are repeated for several resources
$rResource = curl_init();       
curl_setopt($rResource, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($rResource, CURLOPT_URL, $url);
curl_setopt($rResource, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($rResource, CURLOPT_TIMEOUT, 1800);
curl_setopt($rResource, CURLOPT_SSL_VERIFYPEER, false);
curl_multi_add_handle($rMultiHandler, $rResource);
//-----------------------

$iRunningProcesses = null;
do {
    curl_multi_exec($rMultiHandler, $iRunningProcesses);
    usleep(100000);
} while ($iRunningProcesses > 0);

//do some work with received data;

curl_multi_close($rMultiHandler);

The problem is that these requests are time consuming (5-10 minutes). And sometimes one of these requests (the longest) is repeated twice. It seems like curl wait awhile for data, doesn't receive anything and repeats the request. How can I fix this behavior?

The problem was in the wrong configuration Apache and fсgi. After increasing the timeouts problem went away ( timeout for apache, FcgidIOTimeout and FcgidBusyTimeout for fcgi).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM