Reputation: 11
I wonder if there's a way to change the maximum execution time except in the php.ini, because of having issues with scripts taking alot of time to be executed.
I wanted to force a termination via max execution time and set it to values around 30s. The script runtime was exceeded by far. Can't figure out WHEN execatly the script was shut down because of the browser gateway timeout.
I know that after the gateway timeout the script was terminated anyways (otherwise I'd expect protocol entries), but even with "ini_set('max_execution_time', 2);" the browser reaches the gateway timeout. There MUST be an out of php option to regulate the execution time.
The servers OS is ubuntu and I know about the httpd.conf or appache2.conf, but there seem no options regarding the php script runtime to be set.
Upvotes: 0
Views: 99
Reputation: 4180
The script timeout can be set in the script itself by:
set_time_limit ($seconds)
ini_set('max_execution_time', $seconds);
However, your PHP configuration may limit what you can and cannot set from the script. Here is more on how to increase script timeout
If you wish to control and terminate long scripts, it is better to implement it explicitly, e.g.
$executionStartTime = microtime(true);
$timeLimit = 60*5*1000; // 5 minutes
while($whatever)
{
somethingThatTakesALongTime();
if (microtime(true) - $executionStartTime > $timeLimit)
{
throw new Exception("Your loop exceeded the time limit");
}
}
Upvotes: 1