|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2002-12-26 09:32 UTC] bool at boolsite dot net
Hello I have a source which works with PHP 4.1.x to PHP 4.2.x, it's work perfectly. But with PHP 4.3RC4 (windows version, client mode) I have this warning : Warning: socket_read() unable to read from socket [0]: Op?ration r?ussie. in E:\PHP\KioobFTP\v0.7.1\KioobFTP_SocketMode.php on line 262 Then, the result of the function is FALSE. The socket is in blocking mode. The code is : $tmp=socket_read($this->stream,4096,PHP_NORMAL_READ); Do you need others info ? Thanks. Bool PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Oct 30 22:00:01 2025 UTC |
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); ?>Here's a possible patch, but Wez probably knows better if there's a way to tell if a windows socket is in blocking mode... Index: sockets.c =================================================================== RCS file: /repository/php-src/ext/sockets/sockets.c,v retrieving revision 1.171.2.2 diff -u -p -d -r1.171.2.2 sockets.c --- sockets.c 3 Nov 2005 15:00:51 -0000 1.171.2.2 +++ sockets.c 4 Nov 2005 18:28:45 -0000 @@ -257,6 +257,12 @@ static int php_read(int bsd_socket, void int nonblock = 0; char *t = (char *) buf; +/* + * fcntl(s, F_GETFL) will always fail for windows, and there's no way to + * determine if a socket is in blocking mode to my current knowledge, so we + * just omit this check; though that means we're always blocking on win32... + */ +#ifndef PHP_WIN32 m = fcntl(bsd_socket, F_GETFL); if (m < 0) { return m; @@ -264,6 +270,7 @@ static int php_read(int bsd_socket, void nonblock = (m & O_NONBLOCK); m = 0; +#endif set_errno(0);Indeed, it works with : //m = fcntl(bsd_socket, F_GETFL); //if (m < 0) { // return m; //} nonblock = 0; So the fcntl() call makes it fail. But this has the side effect of making the socket_read() call blocking even if the socket has been set to non blocking mode. I will try to make a fully working patch with no side effect when I'll have some time, if no one else is wanting to solve this problem. For the lambda users, here is a usuable dll built against PHP 5.2.3 : http://www.dinsoft.net/dev/php/php_sockets.dll Regards, Dinesh Bolkensteyn