|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #46917 Socket handling completely broken
Submitted: 2008-12-21 16:03 UTC Modified: 2009-10-26 14:15 UTC
Avg. Score:3.8 ± 0.9
Reproduced:6 of 6 (100.0%)
Same Version:5 (83.3%)
Same OS:5 (83.3%)
From: jost_boekemeier at users dot sf dot net Assigned:
Status: Open Package: Streams related
PHP Version: 5.2.8 OS: win32 only
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2008-12-21 16:03 UTC] jost_boekemeier at users dot sf dot net


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2008-12-21 16:07 UTC] jost_boekemeier at users dot sf dot net
The relevant part of the bug trace was missing. 

poll([{fd=16, events=POLLIN|POLLPRI|POLLERR|POLLHUP}], 1, 0) = 1 ([{fd=16, revents=POLLIN}])
recv(16, ""..., 1, MSG_PEEK)            = 0
send(16, "PUT /JavaBridge/JavaBridge.phpjavabridge HTTP/1.1\r\nHost: localhost\r\nContent-Length: 40\r\nX_JAVABRIDGE_CHANNEL: /dev/shm/.php_java_bridgexN2WsO\r\n\r\n\177C<H p=\"1\" v=\"\"></H>"..., 185, 0) = 185
poll([{fd=16, events=POLLIN|POLLERR|POLLHUP}], 1, -1) = 1 ([{fd=16, revents=POLLIN|POLLERR|POLLHUP}])
recv(16, ""..., 8192, 0)                = 0
 [2008-12-24 19:48 UTC]
Thank you for this bug report. To properly diagnose the problem, we
need a short but complete example script to be able to reproduce
this bug ourselves. 

A proper reproducing script starts with <?php and ends with ?>,
is max. 10-20 lines long and does not require any external 
resources such as databases, etc. If the script requires a 
database to demonstrate the issue, please make sure it creates 
all necessary tables, stored procedures etc.

Please avoid embedding huge scripts into the report.

 [2008-12-26 17:28 UTC] jost_boekemeier at users dot sf dot net

 [2009-01-02 21:31 UTC]
Hi, I've commited a probable fix, I initialized the errno.

Can you test it with a cvs version again?
 [2009-01-03 16:45 UTC] jost_boekemeier at users dot sf dot net
Yes, this patch fixes the problem on Linux.

What about Windows?

Jost Boekemeier
 [2009-01-03 17:00 UTC]
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
Thank you for the report, and for helping us make PHP better.

I added the Win part minutes ago:
-#ifndef PHP_WIN32
+/* Reseting/initializing */
+#ifdef PHP_WIN32
+	WSASetLastError(0);
 	errno = 0;

Ok, then, closed. Thanks.
 [2009-01-06 16:15 UTC] jost_boekemeier at users dot sf dot net

the code is okay for Linux, but on Windows it fails constantly.

+	WSASetLastError(0);
 	n = select(max_fd + 1, &rset, &wset, &eset, timeout >= 0 ? &tv : NULL);

IMHO this means that select always returns EAGAIN on windows, so that the following test cannot detect a broken connection. As I've said, I am not sure what the EAGAIN test should do, anyway.

To reproduce this: 

1) start a simple socket server on windows >= xp, call pfsockopen() and let the PHP instance return to the HTTP server's pool w/o closing the connection

2) kill the socket server and start it again

3) pull the PHP instance from the pool and call pfsockopen() again. pfsockopen() will use the broken connection until you kill the pool (i.e.: restart apache or IIS).

Jost Bökemeier
 [2009-01-06 17:41 UTC]
Currently the WSASetLastError(0); already exists for Windows in the code.
 [2009-01-06 19:15 UTC] jost_boekemeier at users dot sf dot net
Well, the initialization is okay now.

However, the code still doesn't work on windows. Which means that there's another bug.

The php_socket_errno() != EAGAIN looks 	suspicious.

"Depending on whether your socket is blocking or non-blocking, you 
either get FD_CLOSE notification, or recv() returns 0 (graceful 
disconnection), or recv() returns WSAECONNRESET error."

I don' see how the current code handles these three cases properly.
 [2009-01-06 19:51 UTC] jost_boekemeier at users dot sf dot net
The windows equivalent to EAGAIN is EWOULDBLOCK or WSAEWOULDBLOCK. 

Could it be that EAGAIN is 0 on windows?

Unfortunately I don't have the time and resources to debug this at the moment.
 [2009-01-07 20:44 UTC]
I changed the EGAIN to EWOULDBLOCK in the checking.
 [2009-01-10 16:12 UTC] jost_boekemeier at users dot sf dot net

 [2009-10-24 00:57 UTC]
 please refer to bug #49447 ( where I have attempted to resolve this issue.

 i am not sure, if you tried with php 5.2.11 or with recent snapshot and let me know if this resolved your issue
 [2009-10-26 14:06 UTC] jost_boekemeier at users dot sf dot net
Using the test above I get:

array(4) { ["type"]=>  int(8) ["message"]=>  string(112) "fwrite(): send of 1 bytes failed with errno=10054 Eine vorhandene Verbindung wurde vom Remotehost geschlossen. " 

So the bug is still there, I think. pfsockopen should transparently check the socket error code and allocate a new connection if the previous persistent connection has an error.

I have tested this on Win XP and PHP 5.2.11 download.
 [2009-10-26 14:15 UTC] jost_boekemeier at users dot sf dot net
Err, 5.2.11 still uses the old code, doesn't it?

With 5.3dev, Build Date 	Oct 26 2009 13:56:57, I get:

array(4) { ["type"]=> int(2) ["message"]=> string(346) "fwrite(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'Europe/Paris' for '1.0/no DST' instead" ["file"]=> string(89) "C:\Programme\Apache Software Foundation\Tomcat 6.0\webapps\JavaBridgeTemplate554\test.php" ["line"]=> int(11) }
PHP Copyright © 2001-2017 The PHP Group
All rights reserved.
Last updated: Sun Nov 19 01:31:42 2017 UTC