ID: 21197 Comment by: faenr at yahoo dot it Reported By: bool at boolsite dot net Status: Verified Bug Type: Sockets related Operating System: win32 only PHP Version: 4.3.4-dev New Comment:
example from---------------------------------- http://ca2.php.net/manual/en/ref.sockets.php #!/usr/local/bin/php -q <?php error_reporting (E_ALL); /* Allow the script to hang around waiting for connections. */ set_time_limit (0); /* Turn on implicit output flushing so we see what we're getting * as it comes in. */ ob_implicit_flush (); $address = '192.168.1.53'; $port = 10000; if (($sock = socket_create (AF_INET, SOCK_STREAM, 0)) < 0) { echo "socket_create() failed: reason: " . socket_strerror ($sock) . "\n"; } if (($ret = socket_bind ($sock, $address, $port)) < 0) { echo "socket_bind() failed: reason: " . socket_strerror ($ret) . "\n"; } if (($ret = socket_listen ($sock, 5)) < 0) { echo "socket_listen() failed: reason: " . socket_strerror ($ret) . "\n"; } do { if (($msgsock = socket_accept($sock)) < 0) { echo "socket_accept() failed: reason: " . socket_strerror ($msgsock) . "\n"; break; } /* Send instructions. */ $msg = "\nWelcome to the PHP Test Server. \n" . "To quit, type 'quit'. To shut down the server type 'shutdown'.\n"; socket_write($msgsock, $msg, strlen($msg)); do { if (FALSE === ($buf = socket_read ($msgsock, 2048, PHP_NORMAL_READ))) { echo "socket_read() failed: reason: " . socket_strerror ($ret) . "\n"; break 2; } if (!$buf = trim ($buf)) { continue; } if ($buf == 'quit') { break; } if ($buf == 'shutdown') { socket_close ($msgsock); break 2; } $talkback = "PHP: You said '$buf'.\n"; socket_write ($msgsock, $talkback, strlen ($talkback)); echo "$buf\n"; } while (true); socket_close ($msgsock); } while (true); socket_close ($sock); ?> my system--------------------------------- windows xp, php 5.0.0b2 error------------------------------------- C:\PHP>php server.php PHP Warning: socket_read() [<a href='function.socket-read'>function.socket-read </a>]: unable to read from socket [0]: Operazione completata. in C:\PHP\server.php on line 39 Content-type: text/html X-Powered-By: PHP/5.0.0b2 <br /> <b>Warning</b>: socket_read() [<a href='function.socket-read'>function.socket-r ead</a>]: unable to read from socket [0]: Operazione completata. in <b>C:\PHP\server.php</b> on line <b>39</b><br /> socket_read() failed: reason: Funzione non corretta. Translection------------------------ Operazione completata = operation completed Funzione non corretta = uncorrect function Guesssing--------------------------- The problem isn't fixed in php 5 thank you Previous Comments: ------------------------------------------------------------------------ [2003-08-26 02:00:58] bool at boolsite dot net Ok, this is a short example : (a little echo server) <?php error_reporting(E_ALL); $Port=6669; if(($Sock=socket_create(AF_INET,SOCK_STREAM,0))<=0) { echo 'socket_create() a échoué : ',socket_strerror(socket_last_error($Sock)),"\r\n"; exit; } if(($Ret=socket_bind($Sock,0,$Port))<=0) { echo 'socket_bind() a échoué : ',socket_strerror(socket_last_error($Ret)),"\r\n"; exit; } if(($Ret=socket_listen($Sock,5))<=0) { echo 'socket_listen() a échoué : ',socket_strerror(socket_last_error($Ret)),"\r\n"; exit; } while(true){ $MsgSock=socket_accept($Sock); if($MsgSock===false) { echo 'socket_accept() a échoué : ',socket_strerror(socket_last_error($MsgSock)),"\r\n"; break; } else { echo '=> Debut de la connexion...',"\r\n"; $EndTime=time()+15; do{ $buffer=socket_read($MsgSock,1024,PHP_NORMAL_READ); if($buffer===false) { echo 'socket_read() a échoué : ',socket_strerror(socket_last_error($MsgSock)),"\r\n"; break; } elseif(!$buffer){ continue; } $buffer=trim($buffer); echo '< ',$buffer,"\r\n"; if($buffer=='quit') { break; } $back='You sent : ['.$buffer.']'; echo '> ',$back,"\r\n"; socket_write($MsgSock,$back."\r\n"); } while(time()<$EndTime); @socket_close($MsgSock); echo '=> End...',"\r\n"; } } socket_close($Sock); ?> ------------------------------------------------------------------------ [2003-08-25 20:17:06] [EMAIL PROTECTED] Please provide a complete but short example script that can be used to reproduce this bug. ------------------------------------------------------------------------ [2003-08-25 18:19:27] bool at boolsite dot net It's not the same bugs than http://bugs.php.net/bug.php?id=21760 . Here it's a Win32 PHP version bug only, since the PHP 4.3.0 version, and there is always the bug in the last version 4.3.3. socket_read() always return FALSE, and display this error : "erreur [0] avec socket_read : OpÚration rÚussie." (in english it should be "error [0] with socket_read : operation completed.") maybe it's because of the socket_select() before the socket_read() ? PS : it affects all my codes, but only with PHP 4.3.x Win32 version. On unix or with PHP 4.2.3 all works fine. ------------------------------------------------------------------------ [2003-06-29 21:42:30] [EMAIL PROTECTED] Please do not submit the same bug more than once. An existing bug report already describes this very problem. Even if you feel that your issue is somewhat different, the resolution is likely to be the same. Because of this, we hope you add your comments to the existing bug instead. Thank you for your interest in PHP. The active discussion regarding this bug appears to be here http://bugs.php.net/bug.php?id=21760 let's keep it all in one place. ------------------------------------------------------------------------ [2002-12-26 20:39:22] [EMAIL PROTECTED] If you omit the third parameter to socket_read() it seems to work fine. However, adding PHP_NORMAL_READ causes error as described in the bug report. ------------------------------------------------------------------------ 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/21197 -- Edit this bug report at http://bugs.php.net/?id=21197&edit=1