开发者

PHP executes longer than max_execution_time... sometimes

I have a PHP class, once called, sets the time limit to 60 seconds. The only special thing about this class is that it uses curl_multi_exec().

set_time_limit(60);
ini_set('max_execution_time', 60);

The problem is that under Apache's /server-status page, this page and another one that uses single threaded curl run past their max_executi开发者_如何学Pythonon_time and reach up to 200 seconds, sometimes!

What am I missing? Is there a way to setup Apache to terminate scripts (or even connections) running for longer than say 90 seconds?


From the manual:

The set_time_limit() function and the configuration directive max_execution_time only affect the execution time of the script itself. Any time spent on activity that happens outside the execution of the script such as system calls using system(), stream operations, database queries, etc. is not included when determining the maximum time that the script has been running.

Because curl requests fall under this category, time spent waiting for a request to complete will not be counted. You should set the curl setting CURLOPT_TIMEOUT to a lower value, or monitor the time spent in executing your script yourself.


Aha! When you set that configuration, the ticker resets itself, example:

sleep(10);
set_time_limit(20);
sleep(10);
set_time_limit(5);
sleep(10); // dies after 5 seconds

Total running time is ~30s.

With regards to curl_exec_multi, you can set the CURL timeout option instead of the PHP one. This depends on who would rather die in your opinion - the curl connection, or the full request.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜