#44335 [Fbk->Opn]: fsockopen on localhost on Vista
| From: | php at smarinier dot net | Date: | Wed, 12 Mar 2008 19:06:45 +0000 |
| Subject: | #44335 [Fbk->Opn]: fsockopen on localhost on Vista | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-123238@lists.php.net to get a copy of this message | ||
ID: 44335
User updated by: php at smarinier dot net
Reported By: php at smarinier dot net
-Status: Feedback
+Status: Open
Bug Type: Network related
Operating System: Windows Vista
PHP Version: 5.2.5
New Comment:
In fact, rebooting Vista, and trying the new PHP, i see the things
working with 127.0.0.1. So this is in fact the "localhost" => 127.0.0.1
resolution wich is a problem.
This is due to the fact that Vista added "::1 localhost" in its
/etc/hosts file. This make (i don't know why) PHP5 failing on the
connection, but php4.4.8 works with this. All of this seems to be an
IPV6/IPV4 mess.
Previous Comments:
------------------------------------------------------------------------
[2008-03-11 21:54:40] jani@php.net
Please try using this CVS snapshot:
http://snaps.php.net/php5.2-latest.tar.gz
For Windows (zip):
http://snaps.php.net/win32/php5.2-win32-latest.zip
For Windows (installer):
http://snaps.php.net/win32/php5.2-win32-installer-latest.msi
------------------------------------------------------------------------
[2008-03-05 11:16:54] php at smarinier dot net
Description:
------------
A Localhost (or 127.0.0.1) connection with fsockopen failed on Vist
(see simple code later). As far as i can see, this:
- doesn't work with php 5.2.5, 5.2.1, 5.1.6, 5.0.3 : on Vista
- works with PHP 4.4.8 on Vista, or with any PHP on Windows Server
2003.
This is not the same problem as the getaddrinfo(localhost)->127.0.0.1,
wich is a (stupid) security protection from Windows.
Reproduce code:
---------------
<?php
$fp = fsockopen('localhost', 80, $errno, $errstr, 30);
if (!$fp) {
echo "$errstr ($errno)<br />\n";
} else {
$out = "GET / HTTP/1.1\r\nHost: localhost\r\nConnection:
Close\r\n\r\n";
fwrite($fp, $out);
while (!feof($fp)) {
echo fgets($fp, 128);
}
fclose($fp);
}
?>
Expected result:
----------------
X-Powered-By: PHP/4.4.8
Content-type: text/html
Content<br/>HTTP/1.1 200 OK
Date: Wed, 05 Mar 2008 10:46:31 GMT
Server: Apache/2.2.8 (Win32) PHP/5.2.1
Last-Modified: Sat, 20 Nov 2004 13:16:26 GMT
ETag: "100000000be49-2c-3e9506e38be80"
Accept-Ranges: bytes
Content-Length: 44
Connection: close
Content-Type: text/html
<html><body><h1>It works!</h1></body></html>
Actual result:
--------------
PHP Warning: fsockopen(): unable to connect to localhost:80 (A
connection attempt failed \
because the connected party did not properly respond after a period of
time, or \
established connection failed because connected host has failed to
respond
) in C:\PHP\test.php on line 2
A connection attempt failed \
because the connected party did not properly respond after a period of
time, or \
established connection failed because connected host has failed to
respond. (10060)<br />
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=44335&edit=1