|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2004-04-27 23:26 UTC] wesleygoku at hotmail dot com
Description:
------------
The funcions connection_aborted(), connection_status() and register_shutdown_function never work well. Using an infinite while (while (true)) to make my WebChat work, even the user stopping the page load, the script keep running (even when I set ignore_user_abort(0)). When I tried to check the connection with these functions, they always returnet TRUE, or NORMAL, even the register_shutdown_function callback funcion ISN'T called.
And every bug report of this problem says it was corrected (since 2002), but I'm using it TODAY (with everything updated) and the problem persists!
I'm using PHP 4.3.6 as an Apache 2.0.49 module.
Reproduce code:
---------------
set_time_limit(0);
ignore_user_abort(0);
register_shutdown_function("chat_quit");
function chat_quit () {
// some code
exit;
}
echo "<!-- "; for ($i = 0; $i < 20480; $i++) {echo rand(0, 9); } echo " -->\n";
flush();
while (true) {
// Infinite code
}
Expected result:
----------------
When the user hits 'stop', the function 'chat_quit' should be called. Even if I change 'while (true)' to 'while (!connection_aborted())' the loop continues.
Actual result:
--------------
The function is NEVER called.
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Nov 18 22:00:01 2025 UTC |
Apache2 works very well with PHP in most/all cases. register_shutdown_function never worked for me in PHP4.X I just upgraded to PHP5.0.0 and guess what! it works, well, partly: I use the latest Apache2, and the shutdown function *gets* called (woah :p) and connection_abort *does* return the right value ! But, as I said, just partly working. For some reason I don't know about, if your code in the shutdown function is too large or something, or access variable, (its quite weird so im unable to tell what it is exactly), then it doesn't gets executed. Eg, I go PHP launching an application and reading stdout. when the guy close the page i want to kill the app, so i close the fd'd, call proc_terminate and proc_close .. nothing happens. So i tried system("kill -9 ".$pid) (i took the pid as global from another part of the code), and never gets executed either it seems.. So i did system("killall appname"); and this one does works Another weird thing is that php takes 20secs or more to trigger the shutdown function once the page is closed.