Edit report at https://bugs.php.net/bug.php?id=70813&edit=1
ID: 70813
Updated by: cmb@php.net
Reported by: sivann at gmail dot com
Summary: connection_status(), connection_aborted() not
working
Status: Feedback
Type: Bug
Package: Network related
Operating System: Fedora 22
PHP Version: 5.6.14
Assigned To: cmb
Block user comment: N
Private report: N
New Comment:
> The script never stops running.
This is what I cannot reproduce.
Previous Comments:
------------------------------------------------------------------------
[2021-10-07 12:31:31] cmb@php.net
I cannot reproduce that with PHP-7.4 on Windows, neither with
httpd nor with the built-in server. Is this still an issue for
you with any of the actively supported PHP versions[1]?
> connection_status(), connection_aborted () never detect closed
> remote connection.
You must ignore user aborts for these functions to work as
expected[2].
[1] <https://www.php.net/supported-versions.php>
[2] <https://www.php.net/manual/en/features.connection-handling.php>
------------------------------------------------------------------------
[2015-10-29 15:11:42] sivann at gmail dot com
httpd-2.4.16 (apache)
------------------------------------------------------------------------
[2015-10-29 14:59:55] sivann at gmail dot com
Description:
------------
connection_status(), connection_aborted () never detect closed remote connection.
After closing connection initiated from client (e.g. wget) connection state becomes CLOSE_WAIT from
ESTABLISHED, but those two functions called in a loop never detect that, even when outputing data.
Current solution is to popen netstat, or parse /proc/net/tcp, /proc/net/tcp6 to find if connection
is established.
connection_status/connection_aborted should detect the connection loss even without writing
anything. Currently those functions do nothing.
Test script:
---------------
<?php
ignore_user_abort(false);
function fecho($str) {
file_put_contents("conlog.txt",$str."",FILE_APPEND);
}
while (1) {
sleep (1);
$d=date(DATE_RFC2822);
$remport=$_SERVER['REMOTE_PORT'];
$remip =
$_SERVER['REMOTE_ADDR']?:($_SERVER['HTTP_X_FORWARDED_FOR']?:$_SERVER['HTTP_CLIENT_IP']);
file_put_contents("conlog.txt","date:$d\tip:$remip\tport:$remport\tstatus:$constatus\n",FILE_APPEND);
echo "...\n";
flush();
if (connection_status()!= CONNECTION_NORMAL){ //never works
file_put_contents("conlog.txt","connection closed\n",FILE_APPEND);
break;
}
file_put_contents("conlog.txt","connection_status=".connection_status().
" connection_aborted():".connection_aborted()."\n",FILE_APPEND);
}
?>
Expected result:
----------------
The above writes on a file named conlog.txt. Call the above script with wget. The script should
start writing data to conlog.txt at the server. Then press Ctrl+C to stop wget. The script should
end.
Actual result:
--------------
The script never stops running.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=70813&edit=1