PHP takes longer than max_execution_time ... sometimes

I have a PHP class that once is called that sets a time limit of 60 seconds. The only feature of this class is that it uses curl_multi_exec ().

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

The problem is that on the Apache / server status page this page and another, using a single stream with a swirl, pass by their max_execution_time and reach 200 seconds, sometimes!

What am I missing? Is there a way to configure Apache to complete scripts (or even connections) that run longer than 90 seconds?

+4
source share
2 answers

From the manual :

The set_time_limit() function and the max_execution_time configuration directive only affect the execution time of the script itself. Any time spent on activity that occurs outside the execution of the script, such as system calls using system() , thread operations, database queries, etc. They are not included when determining the maximum time during which the script is executed.

Since curl requests fall into this category, the time expected to complete the request will not be counted. You must set the curl setting CURLOPT_TIMEOUT to a lower value or control the time taken to execute your script yourself.

+4
source

Yeah! When you set this configuration, the ticker is reset, for example:

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

Total run time ~ 30 s.

As for curl_exec_multi , you can set the curl_exec_multi timeout parameter instead of PHP. It depends on who is likely to die, in your opinion, a curl or a complete request.

+2
source

All Articles