2

I have the following code inside a file (I'm running it directly via Terminal or I access the webpage, it makes no difference).

error_reporting(E_ALL ^ E_NOTICE);
ini_set('display_errors', true);
ini_set('max_execution_time', 1);
ini_set('memory_limit', '512M');
sleep(2);
echo ini_get('max_execution_time');

And it outputs 1. Should it not throw an error, saying that the execution time was excedeed?

From phpinfo() I get:

max_execution_time  1   55
memory_limit    512M    1024M
0

1 Answer 1

2

sleep() time does not count toward execution time because it is not executing any code while it is sleeping.

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(), 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.

This includes sleep(), as is mentioned several times in the comments for both sleep() and for set_time_limit(), e.g.

riki151205-Jun-2007 05:29

Please note that, under Linux, sleeping time is ignored, but under Windows, it counts as execution time.

Sign up to request clarification or add additional context in comments.

2 Comments

wow! thanks a lot! actually I was using a system() command that I saw was taking way too long and was wondering why the script wasn't stopped. Any idea if the memory_limit influences the system() command?
If you're using the second argument to exec(), then it's retrieving each line of output from the executed command to that array, so it will use PHP memory

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.