Re: [PHP-DEV] Make set_time_limit() timeout a catchable fatal error

2011-03-09 Thread Hannes Landeholm
Yes.. apparently it works. My mistake. I accidentally tested it in a context with error suppression enabled. Apparently there where some other reason for it not being gracefully caught in production then. Going to have an extra look at it. Closing the bug in the meantime. ~ Hannes On 9 March 201

Re: [PHP-DEV] Make set_time_limit() timeout a catchable fatal error

2011-03-09 Thread Ferenc Kovacs
tyrael@devel-tyrael:~/c$ php -f fatal.php PHP Fatal error: Call to a member function bar() on a non-object in /home/tyrael/c/fatal.php on line 9 PHP Stack trace: PHP 1. {main}() /home/tyrael/c/fatal.php:0 Houston we have a problem: Array ( [type] => 1 [message] => Call to a member functi

Re: [PHP-DEV] Make set_time_limit() timeout a catchable fatal error

2011-03-09 Thread Hannes Landeholm
No you can't gracefully handle all fatal errors. The shutdown function will be called after *some* fatal errors but not all of them. See the bug I reported here for more information: http://bugs.php.net/bug.php?id=54195 ~Hannes On 9 March 2011 16:12, Ferenc Kovacs wrote: > FYI you can gracefull

Re: [PHP-DEV] Make set_time_limit() timeout a catchable fatal error

2011-03-09 Thread Sebastian Bergmann
On 03/08/2011 09:02 AM, Jared Williams wrote: Would pcntl_alarm() work? I think it does. Just hacked up https://github.com/sebastianbergmann/php-invoker but I need to do some more testing to make sure that it actually works the way want it to. Thanks! Sebastian -- Sebastian Bergmann

Re: [PHP-DEV] Make set_time_limit() timeout a catchable fatal error

2011-03-09 Thread Ferenc Kovacs
FYI you can gracefully handle every error. even the non-recoverable ones. if you check my library you can test it also, I have an example file for every non recoverable error (E_PARSE, E_CORE_ERROR, etc.). from my point of view, every userland error should be catchable from userland. the max execu

Re: [PHP-DEV] Make set_time_limit() timeout a catchable fatal error

2011-03-09 Thread Hannes Landeholm
Yes, it's possible to measure the "time left" yourself. However set_time_limit documentation states that not all time are accounted for when measuring how long the script can run for. If it's a UNIX system and you're using system operations/database queries etc there will be a difference between th

Re: [PHP-DEV] Make set_time_limit() timeout a catchable fatal error

2011-03-09 Thread Hannes Landeholm
That's not a problem. Timeouts should be non-recoverable IMO as it's a serious problem and I think most PHP developers would agree with this. Making errors "recoverable" is difficult to implement, could have performance penalties and be conceptually wrong when the state is defined as "never allowed

Re: [PHP-DEV] Make set_time_limit() timeout a catchable fatal error

2011-03-09 Thread Thomas Hruska
On 3/9/2011 6:56 AM, Hannes Landeholm wrote: A simple way to implement this would be to register a function that would be called N seconds before the script would timeout. register_timeout_handler(2, function() { die("PHP timed out."); }); It would be called just as a shutdown function - in fac

Re: [PHP-DEV] Make set_time_limit() timeout a catchable fatal error

2011-03-09 Thread Ferenc Kovacs
no, it only means that you cant return to the original scope and continue the execution of your script. as you can't throw exceptions also, because your code is running without a stack frame. you can check out the https://github.com/Tyrael/php-error-handler its a little class which operates with re

Re: [PHP-DEV] Make set_time_limit() timeout a catchable fatal error

2011-03-09 Thread Hannes Landeholm
You mean the shutdown function is called and 1 nanosecond later PHP crashes so you don't have time to do anything? ~Hannes On 9 March 2011 15:27, David Muir wrote: > Hmm, I think I worded that poorly. > A function registered with register_shutdown_function does execute when > the max_execution_

Re: [PHP-DEV] Make set_time_limit() timeout a catchable fatal error

2011-03-09 Thread Hannes Landeholm
I'm personally a fan of errors and well defined return values. Exceptions doesn't solve any problem unless your problem is that your code is not enough spaghetti-ish. But I agree with "All fatal errors should be changed to catchable fatal errors". ~Hannes On 9 March 2011 15:18, Martin Scotta wr

Re: [PHP-DEV] Make set_time_limit() timeout a catchable fatal error

2011-03-09 Thread David Muir
Hmm, I think I worded that poorly. A function registered with register_shutdown_function does execute when the max_execution_time is exceeded. What it doesn't let you do is to recover in the same way an error handler would let you. David On 09/03/11 22:56, Hannes Landeholm wrote: > I second makin

Re: [PHP-DEV] Make set_time_limit() timeout a catchable fatal error

2011-03-09 Thread Martin Scotta
Fatal error are most dumb feature in the language. The are lot of "blind" areas where you don't know if you will ever return... include "file.php"; new Class(); call_func(); All fatal errors should be changed to "catchable fatal errors" so applications will be able to recover themselves... and i

Re: [PHP-DEV] Make set_time_limit() timeout a catchable fatal error

2011-03-09 Thread Hannes Landeholm
I second making time limit reached catchable. All non catchable fatal errors are a problem for me. I need to handle problems gracefully to ensure the stability of production systems instead of PHP just killing itself without warning. I just reported a similar issue: http://bugs.php.net/bug.php?id=5

Re: [PHP-DEV] Make set_time_limit() timeout a catchable fatal error

2011-03-08 Thread David Muir
Although it doesn't let you recover from a timeout, you could use register_shutdown_function to gracefully exit after a fatal error. register_shutdown_function(function(){ $error = error_get_last(); if($error && $error['type'] === E_ERROR){ echo 'PHAIL! Oh noes, something went wron

RE: [PHP-DEV] Make set_time_limit() timeout a catchable fatal error

2011-03-08 Thread Jared Williams
Hi, Would pcntl_alarm() work? Jared > -Original Message- > From: Sebastian Bergmann [mailto:sebast...@php.net] > Sent: 08 March 2011 13:06 > To: internals@lists.php.net > Subject: [PHP-DEV] Make set_time_limit() timeout a catchable > fatal error > > C

Re: [PHP-DEV] Make set_time_limit() timeout a catchable fatal error

2011-03-08 Thread Pierre Joye
hi, is not the goal of this setting to prevent that a script runs longer than a given time? A catchable error will prevent that to happen. On Tue, Mar 8, 2011 at 2:05 PM, Sebastian Bergmann wrote: >  Could set_time_limit() be changed in such a way that it triggers a >  catchable fatal error inst

[PHP-DEV] Make set_time_limit() timeout a catchable fatal error

2011-03-08 Thread Sebastian Bergmann
Could set_time_limit() be changed in such a way that it triggers a catchable fatal error instead of a fatal error? Thanks! -- Sebastian BergmannCo-Founder and Principal Consultant http://sebastian-bergmann.de/ http://thePHP.cc/ -- PHP Internals - P