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

From: Date: Wed, 02 Aug 2017 08:41:18 +0000
Subject: Bug #69008 [Com]: socket_read() never returns false when client disconnects with PHP_BINARY_READ
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-210450@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=69008&edit=1 ID: 69008 Comment by: emilien dot calmels at gmail dot com Reported by: sjaillet at gmail dot com Summary: socket_read() never returns false when client disconnects with PHP_BINARY_READ Status: Open Type: Bug Package: Sockets related Operating System: Ubuntu 14.04.1 PHP Version: 5.6.5 Block user comment: N Private report: N New Comment: I've got same problem in php 7.0.16-3 (cli) on Debian 8. This bug has been reported several times for 17 years and hasn't been fixed in 2017! Please do something Previous Comments: ------------------------------------------------------------------------ [2015-02-07 23:39:21] sjaillet at gmail dot com 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 this bug report at https://bugs.php.net/bug.php?id=69008&edit=1

« previous php.bugs (#210450) next »