note 112746 added to function.register-shutdown-function

From: Date: Fri, 19 Jul 2013 08:13:46 +0000
Subject: note 112746 added to function.register-shutdown-function
Groups: php.notes 
Request: Send a blank email to php-notes+get-195671@lists.php.net to get a copy of this message
If you use register_shutdown_function under fastCGI (using php 5.4.4, Apache 2.2/Debian) and the user clicks cancel request in the browser register_shutdown_function will not be called. My solution was to use ignore_user_abort(true) to ignore the user abort. Example (you may test request abort in the browser with and without ignore_user_abort): <?php // use this to make sure the shutdown function will be called ignore_user_abort(true); $f = fopen("debug.out.txt", "wt"); function qShutdown() { global $f; // use __DIR__ as the shutdown it's not invoke under the same folder file_put_contents(__DIR__. "/qShutdown.txt", "qShutdown called"); fwrite($f, "I was called\n"); fclose($f); echo "I was called\n"; } register_shutdown_function("qShutdown"); // do some random stuff echo "things were executed\n"; fwrite($f, "things were executed\n"); fflush($f); $n = 10; $i = 0; while ($i < $n) { sleep(1); $i++; echo "Working {$i} ...\n"; fwrite($f, "Working {$i} ...\n"); fflush($f); ob_flush(); flush(); ob_flush(); } fwrite($f, "die called\n"); fflush($f); die("die called\n"); ?> ---- Server IP: 69.147.83.199 Probable Submitter: 86.123.190.3 ---- Manual Page -- http://php.net/manual/en/function.register-shutdown-function.php Edit -- https://master.php.net/note/edit/112746 Del: integrated -- https://master.php.net/note/delete/112746/integrated Del: useless -- https://master.php.net/note/delete/112746/useless Del: bad code -- https://master.php.net/note/delete/112746/bad+code Del: spam -- https://master.php.net/note/delete/112746/spam Del: non-english -- https://master.php.net/note/delete/112746/non-english Del: in docs -- https://master.php.net/note/delete/112746/in+docs Del: other reasons-- https://master.php.net/note/delete/112746 Reject -- https://master.php.net/note/reject/112746 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#195671) next »