2

I am running scripts that last longer than the limit allowed by the server and the server does not terminate them.

The phpinfo() showed me that the max_execution_time is set to 30. Using the ini_get('max_execution_time') feature the value 30 is displayed, but I put the code with sleep(45) and it runs until the end.

I also tried decreasing the time with ini_set('max_execution_time', 15), but still the code runs normally with sleep(45).

I've used sleep for testing purposes, but this is with functions that use cURL or even foreach and while that are used to create files for users.

What could be changing the server's maximum execution time?

Tom
  • 641
  • 2
  • 8
  • 21

1 Answers1

2

"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."

Copied from: sleep().

In other words: Sleep() was a bad choice for testing maximum execution time.

KIKO Software
  • 15,283
  • 3
  • 18
  • 33
  • I think I will have to create a long while to do this test. – Tom Feb 16 '22 at 18:30
  • @Tom: Yes, something that keeps PHP busy for a while. Generating a lot of output, in a complicated manner, also helps. The advantage of using output is that I'm sure that PHP is checking it's execution time when you do that. – KIKO Software Feb 16 '22 at 18:32
  • If you are testing, just have PHP curl into a custom script of your own writing that performs the sleep. Your calling function will be bound to max execution time from the curl request. – Chris Haas Feb 16 '22 at 19:36