ID: 33568 Updated by: [EMAIL PROTECTED] Reported By: shaun at verticalevolution dot com -Status: Assigned +Status: Feedback Bug Type: Sockets related Operating System: Windows XP SP2 PHP Version: 5CVS-2005-07-05 Assigned To: wez New Comment:
Take a look through these slides: http://netevil.org/talks/index.php?t=lucky-dip Pay particular attention to the part that talks about feof() and network streams. (hint: use stream_get_contents()) Previous Comments: ------------------------------------------------------------------------ [2005-07-05 14:33:12] shaun at verticalevolution dot com Please note also that I've tried the new scripts with the CVS snapshot as well. PHP Version: 5.1.0-dev ------------------------------------------------------------------------ [2005-07-05 14:22:22] shaun at verticalevolution dot com I moved the read array into the while script, this was a mistake on my part. This little server script is just a test to try to simplify my over all object. New Server Script: <?php $sock = stream_socket_server('tcp://127.0.0.1:1899', $errno, $errstr); $i = ''; while(1){ $read = Array($sock); $ready = stream_select($read, $write = NULL, $except = NULL, 10); $c = stream_socket_accept($sock); $read[] = $c; var_dump(stream_get_meta_data($c)); while(!feof($c)){ $i .= fread($c, 12); } var_dump(stream_get_meta_data($c)); echo $i; fwrite($c, 'testback'); break; } fclose($sock); ?> I only reason I had the stream_set_timeout in the client script because if I did not then the client just hangs with out ever quiting. I did remove it as per your request and I let it run for about 2 minutes with it never coming back. New Client script: <?php $output = ''; $sock = stream_socket_client('tcp://127.0.0.1:1899',$errcode, $errstr); fwrite($sock, 'test'); while(!feof($sock)){ $output .= fread($sock, 1024); } fclose($sock); echo $output; ?> After this I still don't get the fread every coming back. ------------------------------------------------------------------------ [2005-07-05 13:46:03] [EMAIL PROTECTED] Please also remove the stream_set_timeout() call from your script(s) and note that you are not using stream_select() correctly (the read/write/excep arrays need to be set on *each* call). ------------------------------------------------------------------------ [2005-07-04 21:58:30] [EMAIL PROTECTED] Please try using this CVS snapshot: http://snaps.php.net/php5-latest.tar.gz For Windows: http://snaps.php.net/win32/php5-win32-latest.zip ------------------------------------------------------------------------ [2005-07-04 21:04:51] shaun at verticalevolution dot com Description: ------------ Once the FEOF flag has been triggered on a stream you are unable to then write to that stream. I created a stream_socket_server, accepted a client (stream_socket_accept) then attempted to read all the contents from the stream (while!feof()) I am not able to then write to that same client stream. It appears that once the feof flag has been it the stream is no longer able to be written to. Reproduce code: --------------- SERVER: <?php $sock = stream_socket_server('tcp://127.0.0.1:1899', $errno, $errstr); $read = Array($sock); $i = ''; while(1){ $ready = stream_select($read, $write = NULL, $except = NULL, 10); $c = stream_socket_accept($sock); var_dump(stream_get_meta_data($c)); while(!feof($c)){ $i .= fread($c, 12); } echo $i; fwrite($c, 'testback'); break; } fclose($sock); ?> CLIENT: <?php $output = ''; $sock = stream_socket_client('tcp://127.0.0.1:1899',$errcode, $errstr); fwrite($sock, 'test'); stream_set_timeout($sock, 5); while(!feof($sock)){ $output = fread($sock, 1024); } fclose($sock); echo $output; ?> Expected result: ---------------- On the server I should see "test" printed out then on the client I should see "testback" printed out. ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=33568&edit=1
