php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #44335 fsockopen on localhost on Vista
Submitted: 2008-03-05 11:16 UTC Modified: 2008-03-13 11:49 UTC
From: php at smarinier dot net Assigned:
Status: Not a bug Package: Network related
PHP Version: 5.2.5 OS: Windows Vista
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: php at smarinier dot net
New email:
PHP Version: OS:

 

 [2008-03-05 11:16 UTC] 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 />

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-03-12 19:06 UTC] php at smarinier dot net
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.
 [2008-03-13 11:49 UTC] jani@php.net
Badly configured OS is not a PHP bug -> Bogus.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 08:01:28 2024 UTC