Bug #69008 [NEW]: socket_read() never returns false when client disconnects with PHP_BINARY_READ

From: Date: Sat, 07 Feb 2015 23:39:21 +0000
Subject: Bug #69008 [NEW]: socket_read() never returns false when client disconnects with PHP_BINARY_READ
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-190514@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() never returns false when client disconnects with PHP_BINARY_READ Description: ------------ According to the documentation socket_read() is supposed to return false on error however it never return false when the connection has been reseted by peer. 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: ---------------- Socket_read(): unable to read from socket []: Connection reset by peer bool(false) Actual result: -------------- string(0) "" string(0) "" string(0) "" string(0) "" string(0) "" string(0) "" string(0) "" string(0) "" string(0) "" etc. -- Edit bug report at https://bugs.php.net/bug.php?id=69008&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=69008&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=69008&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=69008&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=69008&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=69008&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=69008&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=69008&r=needscript Try newer version: https://bugs.php.net/fix.php?id=69008&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=69008&r=support Expected behavior: https://bugs.php.net/fix.php?id=69008&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=69008&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=69008&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=69008&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=69008&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=69008&r=dst IIS Stability: https://bugs.php.net/fix.php?id=69008&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=69008&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=69008&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=69008&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=69008&r=mysqlcfg

« previous php.bugs (#190514) next »