|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #8722 non blocking sockets reading doesn't work on WIN32
Submitted: 2001-01-15 14:50 UTC Modified: 2001-05-13 19:21 UTC
From: christophe at winamp dot com Assigned:
Status: Closed Package: Sockets related
PHP Version: 4.0.4pl1 OS: Any Windows OS
Private report: No CVE-ID: None
 [2001-01-15 14:50 UTC] christophe at winamp dot com
i have the following script:

    echo fgets($g_ssock,4096);

if you uncomment the socket_set_blocking line it will work fine on win32, but with non blocking sockets,  feof will always return true. by digging through the code, it appears that fsock.c uses the errno() function for determining any socket error as seen in function php_sockread_internal:

	} else if(nr_bytes == 0 || (nr_bytes < 0 && errno != EWOULDBLOCK)) {
		sock->eof = 1;

the problem is that win32 doesn't report socket errors with _errno() but with WSAGetLastError() so here is my fix:

in fsock.c, line 46, replace:

#ifdef PHP_WIN32
#include <winsock.h>


#ifdef PHP_WIN32
#include <winsock.h>
#undef errno
#define errno (WSAGetLastError())


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2001-04-16 06:38 UTC]
Ill test the patch and commit if it works well. It looks right to me.

 [2001-05-13 19:21 UTC]
This appears to be fixed in latest CVS. (I cant reproduce this with or without your patch). Please try this with latest cvs and reopen if this is not the case.

- James
 [2002-06-27 05:21 UTC] laurent at searchlores dot org
i am experiencing the same bug with php 4.2.1 under win98. 
Just tried latest CVS (4.3.0-dev, build today) and it's still there. 

applying christophe's patch to network.c (php_sockread_internal() has been moved from fsock.c to php_sock_stream_read_internal() in network.c) seems to solve the bug.
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Sun Mar 29 09:01:24 2020 UTC