|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2017-08-02 08:41 UTC] emilien dot calmels at gmail dot com
[2021-07-28 11:18 UTC] cmb@php.net
-Status: Open
+Status: Verified
[2021-07-28 11:18 UTC] cmb@php.net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 25 14:00:01 2025 UTC |
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.