PHP :: Bug #70813 :: connection_status(), connection_aborted() not working
php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #70813 connection_status(), connection_aborted() not working
Submitted: 2015-10-29 14:59 UTC Modified: 2015-10-29 15:11 UTC
Votes:4
Avg. Score:4.5 ± 0.9
Reproduced:3 of 3 (100.0%)
Same Version:1 (33.3%)
Same OS:1 (33.3%)
From: sivann at gmail dot com Assigned:
Status: Open Package: Network related
PHP Version: 5.6.14 OS: Fedora 22
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2015-10-29 14:59 UTC] 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.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-10-29 15:11 UTC] sivann at gmail dot com
httpd-2.4.16 (apache)
 
PHP Copyright © 2001-2018 The PHP Group
All rights reserved.
Last updated: Tue Aug 14 08:01:25 2018 UTC