Bug #69009 [NEW]: socket_read() shouldn't trigger a warning error with PHP_NORMAL_READ
| From: | sjaillet at gmail dot com | Date: | Sat, 07 Feb 2015 23:54:22 +0000 |
| Subject: | Bug #69009 [NEW]: socket_read() shouldn't trigger a warning error with PHP_NORMAL_READ | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-190515@lists.php.net to get a copy of this message | ||
From: sjaillet at gmail dot com
Operating system: Ubuntu 14.04.1
PHP version: 5.6.5
Package: Sockets related
Bug Type: Bug
Bug description:socket_read() shouldn't trigger a warning error with PHP_NORMAL_READ
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 bug report at https://bugs.php.net/bug.php?id=69009&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=69009&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=69009&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=69009&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=69009&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=69009&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=69009&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=69009&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=69009&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=69009&r=support
Expected behavior: https://bugs.php.net/fix.php?id=69009&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=69009&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=69009&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=69009&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=69009&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=69009&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=69009&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=69009&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=69009&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=69009&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=69009&r=mysqlcfg