[nycphp-talk] register_shutdown_function & parameter passing
Fan, Wellington
wfan at VillageVoice.com
Fri Sep 17 17:36:27 EDT 2004
Hmmm....
This is interesting:
<?php
require_once($_SERVER['DOCUMENT_ROOT'].'/session_handlers.php');
$shutdown_params = array();
$_SESSION['name'] = "bob dobbs";
$_SESSION['time'] = date('r');
$shutdown_params['sess'] = $_SESSION;
function bye(){
global $shutdown_params;
if(connection_aborted()){
mail('spam at example.com','script
aborted',print_r($shutdown_params,TRUE));
}
}
register_shutdown_function('bye');
for($i=0; $i< 1e2; $i++){
echo "$i<br>\n";
flush();
$_SESSION['cointoss'] = ($i%2 ? 'heads':'tails');
sleep(1);
}
echo 'Fin!';
?>
I will get 'heads' or 'tails' for my 'cointoss', most of the time. Just to
try it out, I aborted the script right after the it echo'd '1' to the
browser -- the email I got was this:
Array
(
[sess] => Array
(
[name] => bob dobbs
[time] => Fri, 17 Sep 2004 17:31:21 -0400
)
)
!!!
No cointoss! Though you'd expect that it would be written to the SESSION
when the cointoss statement was reached...looks like writes to the SESSION
might be lazy, and maybe thrown away sometimes?
>
> > Is there any way one can pass parameters to the function
> registered by
> > 'register_shutdown_function()'?
>
> No, because you never know when it's going to be called.
>
More information about the talk
mailing list