ID: 33568 Updated by: [EMAIL PROTECTED] Reported By: shaun at verticalevolution dot com -Status: Open +Status: Bogus Bug Type: Sockets related Operating System: Windows XP SP2 PHP Version: 5CVS-2005-07-05 Assigned To: wez New Comment:
And this is not a support forum on HOW to use PHP. Previous Comments: ------------------------------------------------------------------------ [2005-07-05 18:59:38] [EMAIL PROTECTED] Your usage of stream_select() is still wrong. $read_master = array($sock); while (1) { $read = $read_master; stream_select($read...) $c = stream_socket_accept() $read_master[] = $c; } ------------------------------------------------------------------------ [2005-07-05 16:36:15] shaun at verticalevolution dot com I've taken a look at your slides and I've also tried the stream_get_contents instead of the feof. This still does not work. Instead once the client makes the call the server now uses 100% CPU usage and still hangs. Server code: <?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)); $i = stream_get_contents($c, -1); echo $i; fwrite($c, 'testback'); break; } fclose($sock); ?> client code: <?php $output = ''; $sock = stream_socket_client('tcp://127.0.0.1:1899',$errcode, $errstr); fwrite($sock, 'test'); $output = stream_get_contents($sock, -1); fclose($sock); echo $output; ?> ------------------------------------------------------------------------ [2005-07-05 16:10:36] [EMAIL PROTECTED] 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()) ------------------------------------------------------------------------ [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. ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at http://bugs.php.net/33568 -- Edit this bug report at http://bugs.php.net/?id=33568&edit=1