How to Catch the Fatal Error: Maximum Execution Time of 30 Seconds Exceeded in PHP

How to catch the fatal error: Maximum execution time of 30 seconds exceeded in PHP

Your only options are to increase the allowed execution time (setting it to 0 makes it infinite, but that is not recommended) of the script or spawn a new thread and hope for the best.

The reason that this isn't catchable is that it isn't really thrown. No one line of the code actually triggered the error, rather PHP said, "Nope, sorry, this is too long. Time to shut down now." And that makes sense. Imagine having a script with a max execution time of 30 seconds catching that error and taking another 30 seconds... in a poorly designed program, that opens up some rather nasty opportunities to exploit. At a minimum, it will create opportunities for DOS attacks.

Fatal error: Maximum execution time of 30 seconds exceeded. How to handle this error?

You can either increase the maximum execution time by using set_time_limit() or by setting max_execution_time in the php.ini.
Also by setting set_time_limit to 0 you can remove the limit for exceution time.

And if you are using linux you can try with the function register_shutdown_function.This function will be called when the execution time limit is reached.

Fatal error: Maximum execution time of 30 seconds exceeded

Your loop might be endless. If it is not, you could extend the maximum execution time like this:

ini_set('max_execution_time', '300'); //300 seconds = 5 minutes

and

set_time_limit(300);

can be used to temporarily extend the time limit.

PHP Fatal error: Maximum execution time of 60 seconds exceeded in C:\xampp\htdocs\vendor\symfony\process\Pipes\WindowsPipes.php on line 140

You can set max_execution_time in your php.ini:

max_execution_time=300

Or, in your PHP code:

ini_set('max_execution_time', 300); // 5 minutes

Setting it to zero removes the restriction, however apache might also time out in that scenario.

Check the manual
http://php.net/manual/en/info.configuration.php#ini.max-execution-time

This sets the maximum time in seconds a script is allowed to run before it is terminated by the parser. This helps prevent poorly written scripts from tying up the server. The default setting is 30. When running PHP from the command line the default setting is 0.

The maximum execution time is not affected by system calls, stream operations etc. Please see the set_time_limit() function for more details.

You can not change this setting with ini_set() when running in safe mode. The only workaround is to turn off safe mode or by changing the time limit in the php.ini.

Your web server can have other timeout configurations that may also interrupt PHP execution. Apache has a Timeout directive and IIS has a CGI timeout function. Both default to 300 seconds. See your web server documentation for specific details.



Related Topics



Leave a reply



Submit