ID: 32979 User updated by: mjpph at stardust dot fi Reported By: mjpph at stardust dot fi Status: Open Bug Type: CGI related Operating System: Linux (Fedora Core 3) PHP Version: 5CVS-2005-05-08 (dev) New Comment:
The issue is the same when using stream_socket_server. stream_socket_accept works as expected, but if you select the socket it always returns 0, even if there is a pending connection which would be returned with stream_socket_accept. Previous Comments: ------------------------------------------------------------------------ [2005-05-08 22:50:58] mjpph at stardust dot fi Correction to the previous comment. The fread has to be done before every stream_select to obtain any other value from stream_select other than 0. stream_get_meta_data also reports pending data as 0 before the fread and non-zero value right after the 1 byte fread. ------------------------------------------------------------------------ [2005-05-08 22:46:55] mjpph at stardust dot fi Also, adding "fread($c,1);" after stream_socket_client and before the while loop enables correct functionality of the stream_select function from that pont on. ------------------------------------------------------------------------ [2005-05-08 22:18:29] mjpph at stardust dot fi Description: ------------ Using stream_socket_client or stream_socket_server to open a connection fails to report correct values with stream_select. Using fread to get one byte before stream_select suddenly makes stream_select work as expected. Without it stream_select returns 0 changed streams even though there is data waiting. Service used as an endpoint is persistent and doesn't close the connection after it's output. PHP is CLI-version. Reproduce code: --------------- $c = stream_socket_client("tcp://127.0.0.1:80"); while (1) { $streams = array($c); if (stream_select($streams, $write=NULL, $except=NULL, 0, 5000)) { print "Data received\n"; } } // IP:Port can be anything which outputs something after connection. Expected result: ---------------- Text "Data received" after connection and output from the service. The service can be anything which just outputs something right after connect. Actual result: -------------- Nothing. stream_select returns 0 even though there is data waiting. ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=32979&edit=1