Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exact meaning of PHP max_execution_time

The phrase "maximum execution time" is ambiguous: it could mean (a) the elapsed time since the script started, or (b) the total cputime taken by the script (including or excluding the cputime taken by operating system calls).

The very interesting post by kuba here Real max_execution_time for PHP on linux , finds that this depends upon whether PHP is running on Unix or Windows. In essence he finds that on Unix it is (b) and on Windows or Cygwin it is (a).

But, my server is Linux 2.6.32-358.18.1.el6.x86_64 #1 SMP x86_64 x86_64 x86_64 GNU/Linux, and I have a cron job that gets zapped after exactly 30 seconds elapsed time, despite its cpu time being less than 16 seconds:

[Tuesday, 10-Dec-2013 10:22:33 GMT] Begin, cputime=0 secs.
[Tuesday, 10-Dec-2013 10:22:58 GMT] starting zip_close, cputime=10.12946 secs.
[10-Dec-2013 10:23:03 UTC] PHP Fatal error:  Maximum execution time of 30 seconds exceeded in xxx.php on line 149

This contradicts kuba's finding. Mine is PHP 5.3.26 and IU'm measuring cpu time with:

function cputime() {
    $data = getrusage();
    return $data['ru_utime.tv_sec'] + $data['ru_utime.tv_usec'] / 1000000;

Can anyone clarify further?

like image 748
user3000292 Avatar asked Dec 10 '13 11:12

user3000292


People also ask

What is the best value for max_execution_time in PHP?

max_execution_time is set to 60 which is too low. A minimum execution time of 150 seconds is recommended to give the migration process the best chance of succeeding.

What should max_execution_time be?

By default PHPs maximum execution time is set to 30 seconds of CPU time (time spent in streams and system calls are excluded from this).

What is max_execution_time in WordPress?

The max_execution_time in PHP is the amount of time that your WordPress site will spend on a single operation before timing out. The error is the security precaution taken by WordPress. By default, the maximum execution time for PHP is set as 30 seconds.


1 Answers

This depends entirely on your script. getrusage is not a reliable way to measure it. You're confused between 3 measurement methods, not 2:

  1. The absolute time since the startup of the script
  2. The runtime of the script, so 1. minus system calls
  3. Actual time the CPU is busy, so 2. minus other idle times because of wait states and the like

getrusage measures 3, and is not what is documented. As such you're seeing the conflicting results - apparently your script has 14 seconds of general wait states and other inactive periods, without actually yielding completely like you would with system or streaming operations.

As the PHP docs state Windows uses method 1, and *nix systems use method 2. Nobody uses 3 because it doesn't really make sense as a timeout - it would mean timeouts become extremely aggressively tighter when system load is high and wait states rise.

like image 126
Niels Keurentjes Avatar answered Sep 30 '22 22:09

Niels Keurentjes