Alex Rivera | Logout

PHP: set_time_limit() seems to have no effect whatsoever

Asked 2011-03-30T08:52:41.063
9

I'm trying to use PHP's set_time_limit() in a normal PHP apache script (not CLI) to limit its max running time. It's not doing anything with system calls or anything similar, we're not using safe mode (we're the owners but not the admins of the server). This is PHP 5.2.4 on Linux (Ubuntu).

Simple test case:

ini_set('max_execution_time', 1);
set_time_limit(1);
$i=0;
while ($i++<100000000000) {} // or anything other arbitrary that takes time
die('Done');

Expected result: something relating to the script execution time being exceeded

Actual result: Done is printed.

Am I doing something obvious wrong? (By the way, yes, the script really needs to and can run for too long and need to be aborted, it's unfortunately not something that can be avoided. That is not the point here.)

Edit
Report

1 Answer

1

Try having your script actually do something, sleep time isn't counted towards execution time since while the script is sleeping it's not executing.

EDIT : Check out this bugreport http://bugs.php.net/37306 The last comment is that it was fixed in "CVS HEAD, PHP_5_2 and PHP_5_1." so maybe your PHP version has this bug. Maybe you can you try changing the max_input_time.

answered 2011-03-30T09:00:40.440

Your Answer