Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I've been playing around with a system I'm developing and managed to get it to cause this:

Fatal error: Maximum execution time of 30 seconds exceeded

It happened when I was doing something unrealistic, but nevertheless it could happen with a user.

Does anyone know if there is a way to catch this exception? I've read around but everyone seems to suggest upping the time allowed.

like image 798
ingh.am Avatar asked Jul 28 '11 14:07

ingh.am


People also ask

How do you fix max execution time of 30 seconds exceeded?

The easiest solution to this problem is increasing the time limit. Changing it to 300 seconds (5 minutes) is often more than enough. If that doesn't help, you can try setting even higher values for maximum execution time.

How do I fix maximum execution time in PHP?

This is one of the easiest ways to increase the value of the max_execution_time directive. The ini_set function is used to change the value of the configuration directives that are available in the php. ini configuration file. And thus, we can use it to change the value of the max_execution_time directive.


1 Answers

How about trying as PHP documentation (well... at least one of its readers) say:

<?php function shutdown() {  $a = error_get_last();   if ($a == null) {echo "No errors";}  else {print_r($a);} }  register_shutdown_function('shutdown'); ini_set('max_execution_time', 1); sleep(3); ?> 

Have a look at the following links:

  1. http://www.php.net/manual/en/function.set-error-handler.php#106061
  2. http://www.php.net/manual/en/function.register-shutdown-function.php
like image 141
TheJanOnline Avatar answered Sep 21 '22 07:09

TheJanOnline