Edit report at https://bugs.php.net/bug.php?id=30301&edit=1
ID: 30301
Comment by: gustas dot domain at terra dot com dot br
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! 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);
}
...
Previous Comments:
------------------------------------------------------------------------
[2011-08-19 12:41:28] david dot schueler at wapkamera dot de
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
------------------------------------------------------------------------
[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!!!
------------------------------------------------------------------------
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