Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:51632 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 94507 invoked from network); 9 Mar 2011 14:27:54 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 9 Mar 2011 14:27:54 -0000 Authentication-Results: pb1.pair.com header.from=davidkmuir@gmail.com; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=davidkmuir@gmail.com; spf=unknown; sender-id=unknown Received-SPF: unknown (pb1.pair.com: domain gmail.com does not designate 208.113.200.5 as permitted sender) X-PHP-List-Original-Sender: davidkmuir@gmail.com X-Host-Fingerprint: 208.113.200.5 caibbdcaaaaf.dreamhost.com Windows 98 (1) Received: from [208.113.200.5] ([208.113.200.5:45849] helo=homiemail-a41.g.dreamhost.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 22/61-21312-96E877D4 for ; Wed, 09 Mar 2011 09:27:53 -0500 Received: from homiemail-a41.g.dreamhost.com (localhost [127.0.0.1]) by homiemail-a41.g.dreamhost.com (Postfix) with ESMTP id B3CF844C06A for ; Wed, 9 Mar 2011 06:27:50 -0800 (PST) Received: from [192.168.3.3] (softbank221040106178.bbtec.net [221.40.106.178]) (Authenticated sender: david@thefourstooges.com) by homiemail-a41.g.dreamhost.com (Postfix) with ESMTPA id 3064C44C062 for ; Wed, 9 Mar 2011 06:27:50 -0800 (PST) Message-ID: <4D778E63.2060504@gmail.com> Date: Wed, 09 Mar 2011 23:27:47 +0900 User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.14) Gecko/20110223 Lightning/1.0b2 Thunderbird/3.1.8 MIME-Version: 1.0 To: internals@lists.php.net References: <4D7629B5.4090007@php.net> <4D76D849.6000103@gmail.com> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] Make set_time_limit() timeout a catchable fatal error From: davidkmuir@gmail.com (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 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=54195 > > 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 fact I'd like to use the > same function as my shutdown function and get the error with > error_get_last(). Of course set_time_limit(0) could be used in this function > to prevent the timeout of the timeout handler. This does not "prevent" > timeout since set_time_limit could have been called by the script before the > timeout anyway. > > On that note I also miss a function which returns the time the script can > keep running for. If that calculate needs to be calculated to implemented to > implement this, why not make the value available to the PHP script? > > ~Hannes > > On 9 March 2011 02:30, David Muir wrote: > >> 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 wrong!'; >> // do whatever else you need to do before quitting >> } >> }); >> >> Cheers, >> David >> >> On 08/03/11 22:39, Pierre Joye wrote: >>> 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 instead of a fatal error? Thanks! >>>> >>>> -- >>>> Sebastian Bergmann Co-Founder and Principal >> Consultant >>>> http://sebastian-bergmann.de/ >> http://thePHP.cc/ >>>> -- >>>> PHP Internals - PHP Runtime Development Mailing List >>>> To unsubscribe, visit: http://www.php.net/unsub.php >>>> >>>> >>> >> >> -- >> PHP Internals - PHP Runtime Development Mailing List >> To unsubscribe, visit: http://www.php.net/unsub.php >> >>