Bug #69009 [Opn->Nab]: socket_read() shouldn't trigger a warning error with PHP_NORMAL_READ
| From: | cmb@php.net | Date: | Mon, 15 Mar 2021 15:57:14 +0000 |
| Subject: | Bug #69009 [Opn->Nab]: socket_read() shouldn't trigger a warning error with PHP_NORMAL_READ | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-232738@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=69009&edit=1
ID: 69009
Updated by: cmb@php.net
Reported by: sjaillet at gmail dot com
Summary: socket_read() shouldn't trigger a warning error with
PHP_NORMAL_READ
-Status: Open
+Status: Not a bug
Type: Bug
Package: Sockets related
Operating System: Ubuntu 14.04.1
PHP Version: 5.6.5
-Assigned To:
+Assigned To: cmb
Block user comment: N
Private report: N
New Comment:
Returning false on failure plus raising a warning is pretty common
for many PHP functions, and certainly not a bug. If you want to
change this behavior, please pursue the RFC process[1].
[1] <https://wiki.php.net/rfc/howto>
Previous Comments:
------------------------------------------------------------------------
[2015-02-07 23:54:21] sjaillet at gmail dot com
Description:
------------
According to the documentation socket_read() is supposed to return false
on error so the warning message is therefore unnecessary and makes the @socket_read() syntax
mandatory.
Test script:
---------------
<?php
error_reporting(E_ALL);
set_time_limit(0);
ob_implicit_flush();
if (($sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP)) === false) {
echo socket_strerror(socket_last_error()) . "\n";
exit(-1);
}
if (socket_bind($sock, '127.0.0.1', 10000) === false) {
echo socket_strerror(socket_last_error($sock)) . "\n";
exit(-1);
}
if (socket_listen($sock, 5) === false) {
echo socket_strerror(socket_last_error($sock)) . "\n";
exit(-1);
}
$clients = [];
do {
$read = [];
$read[] = $sock;
$read = array_merge($read, $clients);
if (socket_select($read, $write, $except, 10) < 1)
{
continue;
}
if (in_array($sock, $read)) {
if (($client = socket_accept($sock)) === false) {
echo socket_strerror(socket_last_error($sock)) . "\n";
break;
}
$clients[] = $client;
}
foreach ($clients as $key => $client) {
if (in_array($client, $read)) {
if (($buffer = socket_read($client, 1024)) === false) {
unset($clients[$key]);
echo socket_strerror(socket_last_error($client)) . "\n";
}
var_dump($buffer);
}
}
} while (true);
socket_close($sock);
?>
You can reproduce the bug by executing the following command in two different terminals.
Terminal 1:
php server.php
Terminal 2:
nc localhost 10000
Then hit Ctrl+C in the terminal 2 to close the process
Expected result:
----------------
Connection reset by peer
bool(false)
Actual result:
--------------
PHP Warning: socket_read(): unable to read from socket [104]: Connection reset by peer in
/home/jaillet/test.php on line 45
PHP Stack trace:
PHP 1. {main}() /home/jaillet/test.php:0
PHP 2. socket_read() /home/jaillet/test.php:45
Connection reset by peer
bool(false)
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=69009&edit=1