|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2003-08-29 07:18 UTC] wez@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 07:00:01 2025 UTC |
Description: ------------ Fgets() keeps blocking when I try to make a socket from stream_socket_accept() non-blocking. The listening socket is also non-blocking. Reproduce code: --------------- This code is still blocking on the fgets: $conn = @stream_socket_accept($hsock,1,&$host); if (!$conn) return; echo "Got connection from ".$host."\n"; stream_set_blocking($conn,false); $get = ''; $loop = 0; while ($loop <= 10) { $getl = trim(fgets($conn)); $loop++; if (empty($getl)) { echo "End of headers\n"; break; }else{ $get .= $getl."\n"; } } This is the code that created the $hsock : $hsock = stream_socket_server('tcp://'.$bind.':'.$port, $errno, $errstr); if (!$hsock) die ('Listening socket failed: '.$errstr); if (!socket_set_blocking($hsock,false)) echo "Socket (listening) set nonblock failed\n"; $bind is 0.0.0.0 and port is 3333 Expected result: ---------------- It shouldn't hang on the fgets() because this script handles two sockets. And the other one times out when fgets() hangs untill something is recieved. Actual result: -------------- Fgets() keeps blocking so my other connection times out.