Re: register_shutdown_function - uses for
| From: | CC Zona | Date: | Tue, 10 Apr 2001 19:25:09 +0000 |
| Subject: | Re: register_shutdown_function - uses for | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-48070@lists.php.net to get a copy of this message | ||
In article
<5CEAD14A5163D211A21B0008C7246294015B7E46@ciren-mbx1.BRANN.CO.UK>,
Euan.Greig@brann.com ("Greig, Euan") wrote:
> I was hoping that I could use this function to enable me to finish scripts
> tidily when they time out or are aborted by the user. eg display the message
> "script timed out". However this will not work as no output is allowed in the
> shutdown function. I can see other ways to do what I want (but suggestions
> would always be welcome) but the real point of this email is this: what sort
> of thing would you use register_shutdown_function to achieve?
Not a fancy example, but...
I use it in a script which loops through a database of urls to validate
them. With each loop, set_time_limit gets reset for a length of time more
than sufficient for processing a valid url. If an iteration takes too
long, the script will timeout and die without an error message. Since in
this case timeout == bad url, register_shutdown_function() allows me to
send a final query back to the database marking the current url as invalid.
Otherwise, when I start the script up again it would always have that same
url sitting at the top of the processing list where it would just timeout
over and over again (which is what it used to do--what a PITA).
You could also use register_shutdown_function() to, for instance, email
yourself information about why a script terminated and what state it was
left in. Output to the *browser is disallowed, but output to other
destinations (logs, email, filesystem, databases, etc.) still works. You
can take advantage of that.
--
CC