0

I am calling shell commands that might take a while and should be interrupted after 5 minutes. Anyways, this does not seem to work.

I boiled it down to the following test code:

<?php

set_time_limit(1);
echo 'TL = ' . set_time_limit(1) . PHP_EOL;
sleep(5);
echo 'finished, not interrupted';

This gives me the following output:

TL = 1 finished, not interrupted

So it looks the timelimit is set properly - but the script still runs for 5 seconds.

I am using PHP version 5.6.11 with mod_php

Alex
  • 32,506
  • 16
  • 106
  • 171

2 Answers2

1

The PHP time limit is only enforced when the program is actually executing. sleep delays do not necessarily count as such, as per the manual:

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.

Jon
  • 428,835
  • 81
  • 738
  • 806
1

Time spent sleeping does not count towards script execution time.

user229044
  • 232,980
  • 40
  • 330
  • 338