php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #45264 set_time_limit affects max_execution_time
Submitted: 2008-06-13 16:44 UTC Modified: 2008-06-15 16:05 UTC
From: jdm at visi dot com Assigned:
Status: Not a bug Package: Unknown/Other Function
PHP Version: 5.2.6 OS: Windows
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: jdm at visi dot com
New email:
PHP Version: OS:

 

 [2008-06-13 16:44 UTC] jdm at visi dot com
Description:
------------
Calling set_time_limit appears to not function as it is documented. Per the documentation:

When called, set_time_limit() restarts the timeout counter from zero. In other words, if the timeout is the default 30 seconds, and 25 seconds into script execution a call such as set_time_limit(20) is made, the script will run for a total of 45 seconds before timing out. 

According to my test code, it is actually affecting the ini value of max_execution_time. As a result if the time limit is a smaller value, max_execution_time is altered to a smaller value, and script execution time can be cut short.

I tracked this result down through drupal with the gallery2 integration module included where it makes calls to set_time_limit(30), which causes the module administration page to be cut short, even though my max_execution_time is defined to be 300 seconds.

In my environment, the included code produces the following output:

300

30

Reproduce code:
---------------
print '<p>'.ini_get('max_execution_time').'</p>';
set_time_limit(30);
print '<p>'.ini_get('max_execution_time').'</p>';


Expected result:
----------------
I would expect the max_execution_time to either not change or be extended by the amount set in set_time_limit, according to the documented operation of it. i.e., the resulting code should produce either:

300

300

or:

300

330

Actual result:
--------------
The resulting code produces this output:

300

30

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-06-15 11:46 UTC] derick@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

This is correct, if you change it to something else, it should do that. The reason for this is that for some installations the default is unlimited, and you might want to protect parts of your app for running over time.
 [2008-06-15 16:05 UTC] jdm at visi dot com
If that is indeed the case, there is a bug in the documentation that needs to be addressed. Please see my quote of the manual page for set_time_limit:

"When called, set_time_limit() restarts the timeout counter from zero. In other words, if the timeout is the default 30 seconds, and 25 seconds into script execution a call such as set_time_limit(20) is made, the script will run for a total of 45 seconds before timing out."

As you can see from my example code, that is not what is happening. Obviously in my environment where I've got a max_execution_time of 300, calling set_time_limit is changing the maximum execution time to 30, rather than extending it as the documentation states. 

This is not a bogus bug. Either the documentation is incorrect or the implementation underlying the function is incorrect. If calling set_time_limit(30) after the script has run for 30 seconds affects max_execution_time to the point where the script ends up terminating, then set_time_limit is not extending the time as it is documented to do. Evidently there are a lot of developers who have come to rely on the functionality of set_time_limit() as it is documented, as the gallery code, from which I discovered this defect is commented as though it expects set_time_limit() to extend the time limit rather than set it to the value specified in the parameter of the function call.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Mon Dec 29 03:00:01 2025 UTC