Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I've got a dedicated box (so I can edit all settings) running PHP 5.2.16.

I have both Max_execution_time and max_input_time set to under 60, restarted apache (using apachectl -k graceful) but scripts never time out.

I've tested this with two scripts (actually, I first noticed it with 'real' scripts that probably should have timed out but never did)

while (1) { sleep(10); }

and because apparently sleep() doesnt affect max_execution_time() i tried this:

while(1) { file_get_contents($url); }

($url = a large image. i also echoed stuff so i knew it was running)

I can run scripts for over 10 mins.

Things I've checked:

Doing this:

echo ini_get('max_execution_time'); 

echos out 60 (which is from php.ini)

Doing this:

set_time_limit(5); echo ini_get('max_execution_time'); 

echos out 5

but in both cases the script will run and run forever!

  • I've restarted apache
  • I've checked the max_execution_time and max_input_time in /etc/php.ini. as far as i can tell there is no other php.ini.
  • There is nothing in a .htaccess in any 'previous' (higher) directory saying anything about max_execution_time or set_time_limit

And as mentioned this isn't just a problem when I use sleep() - I've noticed that I can upload and process hundreds of files without needing a set_time_limit(0) there.

share|improve this question

migrated from superuser.com Jun 18 '11 at 13:02

This question came from our site for computer enthusiasts and power users.

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

You are probably falling on stream operations when using file_get_contents.

Try with:

while (1) { ;; }
share|improve this answer

According to the PHP Manual if safe_mode is ON, set_time_limit() will have no effect.

share|improve this answer
    
safe mode isn't on –  needbkupfaster Jun 18 '11 at 10:37

Your Answer

 
discard

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