1

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

I have used set_time_limit(60); many times before. But is there anyway of capturing when this is exceeded, at the moment it just bombs with the same old error.

I want to capture it failing and then handle it in my own way?

Community
  • 1
  • 1
Jake N
  • 10,535
  • 11
  • 66
  • 112
  • 2
    I fear the limit is the limit, I'm not aware there is a softlimit you could catch. I'd say you should do some more research and come back to outline what you've found out. E.g. is that a catchable fatal error even? – hakre Sep 29 '12 at 07:53

1 Answers1

4

From comment section in php.net for set_time_limit

<?php
set_time_limit(60);
ob_start();
function shutdown () {
  $out = ob_get_clean();echo $out; // echo output if required
  // do your processing code
}
register_shutdown_function('shutdown');

// your code
?>
air4x
  • 5,618
  • 1
  • 23
  • 36
  • Hmm. I didn't think that would work, but [the code here](http://codepad.org/vCJklBng) actually works on my server (although not on codepad, which may have it's own custom timeout handler). – Jared Farrish Sep 29 '12 at 08:13
  • Here is the demo code on my site, with a one second timeout: http://jfcoder.com/t/timeout.php And the code-behind: http://pastebin.com/FwBBA0qy – Jared Farrish Sep 29 '12 at 08:19
  • @JaredFarrish yes, it works on my server too. `codepad` would be having some mechanism to block long loops and handle timeouts. – air4x Sep 29 '12 at 08:24