0

Everything is in the title, thus after several search I saw that one to pouver to wrestle this error by the php. Thus I look for a solution for not not that my site shows a blank page (I hide the errors), but rather a page with an error: " impossible to realize your request ". However impossible, I thought of making it with ErrorDocument ( htaccess ), but it does not work (in localhost). To make?

Sorry for my English

dadadaa
  • 55
  • 2
  • 9
  • No worries on the English. I actually kinda like it... might be trochee. – ficuscr Jun 04 '15 at 21:10
  • possible duplicate of [How to catch the fatal error: Maximum execution time of 30 seconds exceeded in PHP](http://stackoverflow.com/questions/6861033/how-to-catch-the-fatal-error-maximum-execution-time-of-30-seconds-exceeded-in-p) – ficuscr Jun 04 '15 at 21:11
  • can you provide us a small example or tell us the scenario in which it occurs. e.g it happens when i try to load xyz etc and so on – Pradheep Jun 04 '15 at 21:12

2 Answers2

1

What you need to do is make use of the register_shutdown_function() which will let you do something just before PHP exits.

So in the example below I'm catching errors and checking to see if the message starts with Maximum execution time of

example code

set_time_limit(1);

register_shutdown_function(function() {
    $error = error_get_last();

    if ($error['type'] === E_ERROR && strpos($error['message'], 'Maximum execution time of') === 0) {
        echo 'time limit exceeded';
    }
});

for(;;) {}
Jonathan
  • 2,778
  • 13
  • 23
  • There must be also isset($error['type']) check, because the $error can be null when the handler invoked on exit() etc – ymakux Feb 15 '16 at 05:37
0

You can add error documents to .htaccess. For timeouts, you need to add one for status code 504. Add the following line to .htaccess:

ErrorDocument 504 /504.html

/504.html is the relative url to an error page that you want to show. This may be a PHP file as well.

more information and list of error codes

GolezTrol
  • 114,394
  • 18
  • 182
  • 210