Bug #64644 [Opn->Nab]: Client-side abortion is not detected at all
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 is not detected at all
-Status: Open
+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:
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.
Previous Comments:
------------------------------------------------------------------------
[2013-04-13 18:55:46] matteosistisette at gmail dot com
Description:
------------
PHP Version 5.3.3-7+squeeze14 (for some reason it is not in the dropdown)
I have read and deeply understood these:
http://www.php.net/manual/en/features.connection-handling.php
http://www.php.net/manual/en/function.register-shutdown-function.php
However, neither in 5.1.6 nor in 5.3.3 do things work even close to described
there:
- connection_status() always return true, even after the client has closed the
connection.
- execution of the script keeps going on after the client has closed the
connection, even though ignore_user_abort is 0
- a function registered with register_shutdown_function() is not run until the
script reaches ends. The script is NOT interrupted (and hence the function not
called) when the client aborts the connection.
So basically PHP just doesn't detect the client's disconnection AT ALL.
Note that this is NOT as if ignore_user_abort was set to 1: if that was the case
then connection_status() would return 1 even though the script would keep
running and the shutdown function would not be called until the end. That is not
the case.
ini_get("ignore_user_abort") returns 0, as expected.
I'm observing this both on PHP 5.1.6 on CentOS 5.9, and on PHP 5.3 on Debian
6.0.3
Steps to reproduce:
- put the script below in the public_html folder
- tail -f /path/to/error_log
- visit the url of the php script from a browser or client
- hit the stop button in the browser or abort connection from the client
- watch the error_log
Test script:
---------------
<?php
function myShutdown() {
error_log("myShutdown ".connection_status()."
".ini_get("ignore_user_abort"));
}
register_shutdown_function(myShutdown);
echo "Hi!";
error_log(" *** test/test *** ");
for ($i=0; $i<10; $i++) {
sleep(1);
error_log(".");
echo ".";
}
?>
Expected result:
----------------
Expected:
at the moment when the client abort connection, you should stop seeing new "." in
the log, and you should see immediately: myShutdown 1 0
Actual result:
--------------
Observed:
Exactly 10 dots (".") appear one at every second, even if the client aborts
connection before the 10th dot is reached, and only at the end you see
"myShutdown 0 0"
This differs with the documented behavior. Everything consistently behaves as if
connection from the client was NEVER aborted.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=64644&edit=1
Thread (9 messages)