Bug #70813 [Opn]: connection_status(), connection_aborted() not working

From: Date: Mon, 18 Oct 2021 13:26:19 +0000
Subject: Bug #70813 [Opn]: connection_status(), connection_aborted() not working
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-237265@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=70813&edit=1

 ID:                 70813
 User updated by:    sivann at gmail dot com
 Reported by:        sivann at gmail dot com
 Summary:            connection_status(), connection_aborted() not
                     working
 Status:             Open
 Type:               Bug
 Package:            Network related
 Operating System:   CentOS7
 PHP Version:        7.4.24
 Block user comment: N
 Private report:     N

 New Comment:

It seems adding an ob_flush() after flush() fixes it:
This works:
<?php
ignore_user_abort(true);


$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\n",FILE_APPEND);

while (1) {
    sleep (1);
    $d=date(DATE_RFC2822);
    echo "...\n";
    ob_flush();
    flush();
    file_put_contents("conlog.txt","connection_status=".connection_status(). 
" connection_aborted():".connection_aborted()."\n",FILE_APPEND);
    if (connection_status()!= CONNECTION_NORMAL){ //never works
        file_put_contents("conlog.txt","connection closed\n",FILE_APPEND);
        ob_flush();
        flush();
        break;
    }
}

Maybe a doc edit would be needed to clarify this.

Moreover it would be easy for connection_status() and connection_aborted() to return connection
status without outputting data to the client, by examining /proc/net/tcp (in linux) as we already
have remote IP and port. Very useful to know when to abort long-poll requests. 
But this would be an another improvement ticket I presume.


Previous Comments:
------------------------------------------------------------------------
[2021-10-18 13:02:39] sivann at gmail dot com

checked again with
* mod_php 
* php-fpm
* built-int web server

same thing, those 2 functions always return 0.

------------------------------------------------------------------------
[2021-10-18 10:26:13] cmb@php.net

Okay, maybe someone else is able to reproduce.

------------------------------------------------------------------------
[2021-10-17 07:58:18] sivann at gmail dot com

updated php version

------------------------------------------------------------------------
[2021-10-17 07:57:36] sivann at gmail dot com

trying to reopen

------------------------------------------------------------------------
[2021-10-17 07:56:22] sivann at gmail dot com

I could not update the status to re-opened and it had only the closed option, Please re-open the
bug, I could only post comments if I changed status to closed.

------------------------------------------------------------------------


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=70813


--
Edit this bug report at https://bugs.php.net/bug.php?id=70813&edit=1


Thread (14 messages)

« previous php.bugs (#237265) next »