0

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.

  • Sometimes the best way to stop a script from taking a long time to run is to improve the script itself, can you tell us what it is you're running that is taking so long? – Mark Jan 22 '20 at 10:17
  • See this link help you: https://www.php.net/manual/en/function.set-time-limit – Benilson Jan 22 '20 at 10:31

1 Answers1

1

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");
    }
}
Eriks Klotins
  • 4,042
  • 1
  • 12
  • 26