Edit report at https://bugs.php.net/bug.php?id=70813&edit=1
ID: 70813
Updated by: php-bugs@lists.php.net
Reported by: sivann at gmail dot com
Summary: connection_status(), connection_aborted() not working
-Status: Feedback
+Status: No Feedback
Type: Bug
Package: Network related
Operating System: CentOS7
PHP Version: 7.4.24
Private report: N
New Comment:
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Re-Opened". Thank you.
Previous Comments:
------------------------------------------------------------------------
[2021-10-18 17:22:40] requinix@php.net
Do you have any output buffering enabled? As the docs do already say, PHP detects state when it
tries to output, so if there is buffering then the functions won't be accurate until the buffer
is flushed.
------------------------------------------------------------------------
[2021-10-18 13:26:19] sivann at gmail dot com
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.
------------------------------------------------------------------------
[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
------------------------------------------------------------------------
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