|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2021-04-06 12:30 UTC] cmb@php.net
-Status: Open
+Status: Verified
-Type: Bug
+Type: Documentation Problem
[2021-04-06 12:30 UTC] cmb@php.net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Oct 23 21:00:01 2025 UTC |
Description: ------------ If you call socket_read and it throws an error such as socket error 10035 then the connection will never timeout even if the remote side disconnects. Socket error 10035 is thrown if data is not ready to be read (hasn't been sent) yet and is not really indicative of a disconnect or other fatal error. Maybe there's a distinction to be made between fatal and nonfatal socket errors. Possibly have it return an empty string instead of throwing a nonfatal error? There is no data to read so that seems to be the more appropriate course of action. Test script: --------------- $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); $connected = socket_connect($socket, '127.0.0.1', 1337); // some server that never sends you data. connection must be accepted though, or else this throws an error. socket_set_nonblock($socket); socket_set_option($socket, SOL_SOCKET, SO_RCVTIMEO, array('sec' => 1, 'usec' => 0)); // set timeout to something fast, a second. while (($read = @socket_read($socket, 1)) === false) { // socket_read throwing an error doesn't mean the connection has failed and the server is gone // in context, it just means the server hasn't sent any data yet. [in testing, it never will.] if (socket_last_error($socket) != 10035) break; // an error that probably means we disconnected has been thrown! } echo('yay we did it! '.socket_last_error($socket)); Expected result: ---------------- yay we did it! (some FATAL error code) Actual result: -------------- infinite nothingness unless set_time_limit is set, in which case the typical time limit exceeded error interrupts the script.