Does sleep time count for execution time limit?

Solution 1:

You should try it, just have a script that sleeps for more than your maximum execution time.

<?php
  sleep(ini_get('max_execution_time') + 10);
?>

Spoiler: Under Linux, sleeping time is ignored, but under Windows, it counts as execution time.

Solution 2:

It only affects script time not system calls like sleep(). There is apparently a bug where on Windows sleep() is included. Max execution time is about real-time, not CPU time or anything like that. You can change it however:

  • max_execution_time directive in your php.ini. This is a global setting;
  • Using ini_set() with the above directive. This will change it only for the currently executing script only for that execution;
  • set_time_limit(): also a local change.

As for the difference between the last two, I believe max_execution_time is a fixed quantity. Running:

ini_set('max_execution_time', 60);

will limit to the script to 60 seconds. If after 20 seconds you call:

set_time_limit(60);

the script will now be limited to 20 + 60 = 80 seconds.

Solution 3:

From the PHP sleep() page, there's this user-contributed note:

Note: 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(), the sleep() function, database queries, etc. is not included when determining the maximum time that the script has been running.