|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2004-10-01 14:25 UTC] phpbug at zone-mr dot ath dot cx
Description:
------------
I have seen similar bug reports for Apache2 (where the issue is still unresolved, but none for IIS 6.0).
I have tried two different servers, and both PHP 5.02 and PHP4.39. Each server was running Windows 2003 with IIS 6 and exhibits the same symptons.
Connection_status reports 0, even when the stop button is pressed, and there is no browser listening to the script output. Connection_abort also returns false.
Reproduce code:
---------------
ignore_user_abort(???); //Tried both true and false, no difference
while (connection_status()==0) {
sleep(1);
echo "test\n";
flush();
ob_flush();
... //Log an "I'm still here" timestamp, for debugging
if(connection_aborted()) {
//Log a disconnection into a DB
exit;
}
}
//Log a disconnection into a DB
Expected result:
----------------
When the browser window or connection is closed, I expect the script to stop logging the "I'm still there" message every second, and terminate execution.
Actual result:
--------------
The script continues to run, updating the timestamp every second, until the time limit is reached. Connection_aborted, connection_status seem to indicate the connection is still active (but it isn't - the browser is closed, netstat confirms that there are no connections).
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Oct 28 03:00:02 2025 UTC |
I am having the same problem on SuSE Linux 9.3 running Linux 2.6.11.4-21.9-default, Apache 2.0.53 and PHP 4.3.10 (cli) (built: Aug 31 2005 16:14:46) The script below can be used to recreate the problem. After I have press the Stop button (Firefox 1.0.7) the script continues to execute until it is killed 15 minutes later without the shutdown function being executed. <? function foo() { exec("echo '".date("Y/m/d H:i:s")." Terminating Status:".connection_status()."' >> /tmp/test"); } register_shutdown_function('foo'); exec("echo '".date("Y/m/d H:i:s")." Starting' > /tmp/test"); $count=0; while (true) { $count++; exec("echo '".date("Y/m/d H:i:s")." Running ".$count." Status:".connection_status()."' >> /tmp/test"); } ?>I am having the same problem! I have tried everything. This has not been fixed since Oct 2004?? This is my code: <?php //ob_end_flush(); //This should make it work: set_time_limit(0); ignore_user_abort(false); error_reporting(E_ALL); ini_set("max_execution_time", "0"); $x = 0; $error = fopen("file.txt", "a"); echo "Beginning neverending loop"; //Alternate method register_shutdown_function("help"); while($x < 40) { //ob_end_clean(); //ob_start(); $xx = $x."__Connstat: ".connection_status()."Aborted? ".connection_aborted()."\r\n\r\n"; echo $xx; fwrite($error, $xx, strlen($xx)); //This is written fine. $x++; flush(); //If I include this flush, the program stops when I hit the stop button. If I don't, it doesn't stop even if I hit the stop button. sleep(1); if(connection_status() != 0 || connection_aborted()) { $msg = "QUIT"; fwrite($error, $msg, strlen($msg)); exit(); } } function help() { $f = fopen("test.txt", "a"); $m = "QUIT"; fwrite($f, $m, strlen($m)); fclose($f); exit(); } ?>This problem still exists! I use Apache2 and PHP 5.3.5-pl0-gentoo with Suhosin-Patch as apache module. The script is use: <?php error_reporting(0); ini_set('max_execution_time',300); header('Content-Type: application/json'); echo json_encode(array('timestamp'=>time(),'status'=>'start'))."\n"; $ping = time(); while (true) { echo json_encode(array('timestamp'=>time(),'status'=>'trigger'))."\n"; flush(); if (connection_aborted()) exit; sleep(10); } die(json_encode(array('timestamp'=>time(),'status'=>'errorstop'))); ?> Look what Wireshark says about this: TCP 34878 > 80 [SYN] TCP 80 > 34878 [SYN, ACK] TCP 34878 > 80 [ACK] HTTP GET /testl.php HTTP/1.1 TCP 80 > 34878 [ACK] HTTP HTTP/1.1 200 OK (application/json) TCP 34878 > 80 [ACK] TCP 34878 > 80 [FIN, ACK] <== hitting of browsers STOP button TCP 80 > 34878 [ACK] HTTP Continuation or non-HTTP traffic TCP 34878 > 80 [RST] As you can see, the script is stopped AFTER one more output line is sent to the browser. It responds with a RST packet, because the port is already closed. So connection_aborted() is totally useless. But this behavior is essential for use in server push cases, where one (AJAX) request establishes a connection and waits for long time to get data from the server. But if the browser ends the connection, the script doesn't get informed about that and will loop forever in the worst case. I suppose the Apache webserver does not inform the mod_php about the connection termination, or it's a PHP code issue. Someone of the developers should really have a look at this! DavidThis problem still exists! PHP Version 5.3.8 Firefox and android native browser OR when sleep functions is added on code (ALL browsers), I found this issue. ... while (!feof($fp))) { if ((connection_aborted()) || (connection_status() != 0)) { break; } // usleep(100000); } ...