Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

On Ubuntu 10.10 with Apache2 + php, the script

  system("sleep 10000");

does not time out. Both max_execution_time and TimeOut do not apply.

Is there any way to ensure that a script will be halted?

share|improve this question
  • TimeOut has no effect on mod_php.
  • max_execution_time only affects the execution time of the script itself. System calls using system() or exec() do not count towards the execution time except on Windows.
share|improve this answer

With Apache and mod_php you'll have an issue here. Other methods such as loading php via fcgid or fastcgi would give you greater control over process management / execution time / timeouts / idle time / etc.

share|improve this answer

Alvosu's answer is nearly right - but a bit terse.

PHP's sleep() is a simple wrapper under the OS's scheduler API. When its called, php stops running - so the PHP can't check if the clock has run out until the sleep time expires and the scheduler adds it back onto the run queue, and the CPU gets round to processing the next instruction.

While this example is rather artificial (why would you ever write a script like that knowing you'd got a timeout running) there are many scenarios where the thread of execution passes outside of the PHP interpreter, and it therefore does not get a chance to check its stopwatch - e.g. when the script starts other processes, or the thread is in an extension - such as waiting for a db query to return. The problem can be avoided by asking the system to send a signal back to the PHP code at a defined interval (pcntl_alarm) after you define a signal handler (pcntl_signal).

share|improve this answer
@symcbean where MathGladiator call PHP's sleep()? – alvosu Feb 3 '11 at 15:14
This is very interesting. I'll have to look into this as a more general solution. If I can use this to make it so I can basically kill anything I want, then I'm in business. Ideally, I would have liked a solution that was in Apache2 to guarantee this. – MathGladiator Feb 5 '11 at 20:19
@symcbean system("sleep 10000") not equally sleep(). Read the code in question. – osdyng Feb 6 '11 at 16:03
@osdyng - same thing just via a different route - the sleep commeand (more likely the sheell alias) is just a wrapper around the OS call. – symcbean Feb 6 '11 at 22:51
@symcbean try run system("while true; cat big_file > /dev/null;done"), max_execution_time don't work, but no sleep() call – alvosu Feb 7 '11 at 7:28

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.