Bug #64644 [Nab]: Client-side abortion should be detected regardless of sending output
Edit report at https://bugs.php.net/bug.php?id=64644&edit=1
ID: 64644
Updated by: rasmus@php.net
Reported by: matteosistisette at gmail dot com
Summary: Client-side abortion should be detected regardless
of sending output
Status: Not a bug
Type: Bug
Package: *General Issues
Operating System: Linux
PHP Version: 5.3.24
Block user comment: N
Private report: N
New Comment:
They are basically saying that we could try to hack around Apache and try to
write directly to do direct socket ops on a socket opened and managed by Apache.
Very bad idea. I don't know of any environment that attempts to do this. See
this conversation about the same issue in Django, for example:
http://stackoverflow.com/questions/6019145/how-do-i-detect-an-aborted-
connection-in-django
This isn't something we are going to address with hacks in PHP.
Previous Comments:
------------------------------------------------------------------------
[2013-04-13 23:41:08] matteosistisette at gmail dot com
Response from Apache developers:
https://issues.apache.org/bugzilla/show_bug.cgi?id=54842#c1
I'm not sure I fully understand it but it seems they say there actually IS a way
PHP can figure out if the connection is closed without attempting to write.
------------------------------------------------------------------------
[2013-04-13 22:15:41] matteosistisette at gmail dot com
Unbelievable. Then the huge design flaw is in Apache.
------------------------------------------------------------------------
[2013-04-13 21:59:18] rasmus@php.net
Apache handles the communication with the client browser and provides no
mechanism for PHP to discover a client abort except on an actual write.
------------------------------------------------------------------------
[2013-04-13 21:56:04] matteosistisette at gmail dot com
Ok, I see. The problem is that I hadn't disabled gzip in Apache, so the output
wasn't being flushed until the end. As documented:
"""PHP will not detect that the user has aborted the connection until an attempt
is made to send information to the client. Simply using an echo statement does
not guarantee that information is sent, see flush()."""
However, this is a huge design flaw. PHP definitely should be able to detect the
client's abortion when it happens and not the next time it attempts to actually
send output. Having to change the way output is handled just in order to be able
to detect client disconnection is ridiculous (and not always feasible).
I don't know if the server API currently provides a way for the server (i.e.
Apache) to inform PHP of the client's disconnection, but if there is not it must
be provided.
------------------------------------------------------------------------
[2013-04-13 21:52:32] rasmus@php.net
What you are missing is that your single-character output is getting buffered.
There is no way to detect a client abort until you actually try to send something
to the client either by filling the output buffer and having it send
automatically or by forcing it by calling flush() after your echo. So in your
test case, add a flush() call after your echo "." and you will see it works as
documented.
------------------------------------------------------------------------
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=64644
--
Edit this bug report at https://bugs.php.net/bug.php?id=64644&edit=1
Thread (9 messages)