Why the script does NOT show "Fatal error: Maximum execution time of XX seconds"?

98 views Asked by At

I would like to know why php (I'm using 5.5) doesn't stop this script with a fatal error. Thanks.

<?
set_time_limit(5);
ini_set('max_execution_time', 5);
echo 'hi';
for ($i = 0; $i < 10; $i++){
    sleep(1);
}
echo '<br>bye';
?>

The output of the script is:

hi<br>bye

Without any errors or warnings.

2

There are 2 answers

0
sjagr On BEST ANSWER

From the PHP docs:

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. This is not true on Windows where the measured time is real.

To paraphrase this documentation answer, it basically means that sleep() is not a time consuming function in Linux.

1
Paizo On

Sleep(); on linux is not count by the max execution time, see the user contribution here and the answer on the same question here