Forum Moderators: coopster

Message Too Old, No Replies

register_shutdown_function() post-exit behavior

anyone use this for output?

         

mincklerstraat

1:28 pm on Oct 30, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I've been doing a project that needs to do output after the script is done processing, I've been working on it in flags for quite a long time.
register_shutdown_function()
worked for this on windows, but when I began the project, I had a really old php install on linux, and it didn't produce output. So I had to go through a lot of weird loops like opening a popup that auto-refreshed in a few seconds to a different page that was written by register_shutdown_function(). The manual at the time said (link to Feb. 2004 page at archive.org [web.archive.org]):
The registered shutdown functions are called after the request has been completed (including sending any output buffers), so it is not possible to send output to the browser

Now the manual says:

Since PHP 4.1, the shutdown functions are called as the part of the request so that it's possible to send the output from them.
(php 4.1 was released Dec, 10, 2001)

The archived page above is the latest at archive.org; the 'last modified' date on the new page at php.net is October 28 2004, and it does seem like this page was last updated then (translations not yet updated, Yahoo cache shows old page).

I even remember advising people (might have been here) not to use

register_shutdown_function()
for any kind of output since, as it was specified in the manual not to produced output, this was an 'undefined functionality' likely to be modified (meaning script wouldn't be compatible with future php releases).

Anyways, this is apparently now 'official', offical since the December 2001 release. And great news for anyone who wants to add stuff to their page after PHP is done with the 'normal' execution.

Seeing, though, that it's only been made 'official' so recently, I wonder: has anyone actually used this in coding, does it work consistently, and in what versions of PHP? Here in 4.3.4 it seems to work fine according to the 'new' spec.

jatar_k

8:53 pm on Oct 30, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



never used it myself actually

I can't quite wrap my head around what I would use it for. The only thing I can really think of is some type of function to verify the page was delivered and not stopped, maybe tracking or form verification.

not sure really