Edit report at https://bugs.php.net/bug.php?id=30301&edit=1
ID: 30301
Comment by: david dot schueler at wapkamera dot de
Reported by: phpbug at zone-mr dot ath dot cx
Summary: connection_status and connection_aborted not
working.
Status: No Feedback
Type: Bug
Package: IIS related
Operating System: Windows 2003 Server
PHP Version: 5.0.2
Block user comment: N
Private report: N
New Comment:
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!
David
Previous Comments:
------------------------------------------------------------------------
[2009-11-13 19:34:08] ricardo at haha dot com dot br
I had this problem years ago, now the problem came back after upgrading php... i tried everything i
found and in the end the function ob_end_flush(); on top of script as post here solved the problem.
Im using windows 7 x64 / php 5.2.4 / apache 2.2.14 (win32)
Thanks
------------------------------------------------------------------------
[2008-10-27 17:06:27] ger_stingray427 at yahoo dot com
before year 2004 this function worked ?
maybe we request new feature and this function works, but not as expected for us.
------------------------------------------------------------------------
[2008-09-22 06:41:57] samedi at online dot de
I am having exactly the same problem! (Using PHP 5.2.6)
Four years and this bug does really still exist?
------------------------------------------------------------------------
[2007-06-01 16:50:14] mike at dodgeit dot com
How about fixing this bug thats been open since 2004!!!
------------------------------------------------------------------------
[2007-04-19 05:14:30] benb at dpac dot tas dot gov dot au
I too am experiencing this problem with Apache 2.2.4 and PHP 5.2.1 on Ubuntu. Kernel 2.6.
Using a similar script to the one listed above. Connection_status() returns 0, as does
connection_aborted.
However I am streaming video. When streaming this amount of data, the connection does in fact hang
as the image data can't make it to the client.
I added a shutdown function with register_shutdown_function() to verify this though. Several minutes
after my on-disk log file stops recording data being sent, the shutdown function writes a message to
the same log file to say that the script has finally been terminated.
So i'm assuming that apache is still trying to send data to the client even though they're
no longer listening and it's the apache write_timeout that's finally killing the thread.
Because the script is effectively dead in the water while waiting for data to be received by the
client, i can't put in any timeout code to compensate. So i'm about to try and put a
set_time_limit(10) call before each data transmission so that an output hang is (hopefully) handled
after 10 seconds rather than several minutes.
It would be great though if this was fixed. It would make life so much easier!
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
https://bugs.php.net/bug.php?id=30301--
Edit this bug report at https://bugs.php.net/bug.php?id=30301&edit=1