fsockopen will not work on 'localhost'
| Bug #50953 | fsockopen will not work on 'localhost' | ||||
|---|---|---|---|---|---|
| Submitted: | 2010-02-07 13:31 UTC | Modified: | 2010-09-07 11:48 UTC | ||
| From: | tony at marston-home dot demon dot co dot uk | Assigned: | pajoye (profile) | ||
| Status: | Closed | Package: | Sockets related | ||
| PHP Version: | 5.2.12 | OS: | Windows XP | ||
| Private report: | No | CVE-ID: | None | ||
[2010-02-07 13:31 UTC] tony at marston-home dot demon dot co dot uk
Description:
------------
If I use fsockopen with host 'localhost' it fails, but it works with '127.0.0.1' or any other host name.
Reproduce code:
---------------
function connect($host) {
$faultcode = null;
$faultstring = null;
$conn = fsockopen($host, 80, $faultcode, $faultstring, 20);
if (!$conn) {
echo 'faultcode=' .$faultcode .', faultstring=' .$faultstring ."\n";
} else {
echo "Connected to $host OK\n";
} // if
return $conn;
} // function
$result = connect('localhost');
$result = connect('127.0.0.1');
$result = connect('desktop');
$result = connect('www.tonymarston.net');
Expected result:
----------------
I expect to see the message "Connected to <host> OK" for all values of host.
Actual result:
--------------
Warning: fsockopen(): unable to connect to localhost:80
faultcode=10060, faultstring=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.
Connected to 127.0.0.1 OK
Connected to desktop OK
Connected to www.tonymarston.net OK
Patches
connect_fix_win32 (last revision 2010-09-07 08:26 UTC by cataphract@php.net)Pull Requests
History
AllCommentsChangesGit/SVN commits
[2010-02-07 16:07 UTC] pajoye@php.net
[2010-02-07 16:28 UTC] tony at marston-home dot demon dot co dot uk
[2010-02-07 17:15 UTC] pajoye@php.net
[2010-02-07 17:27 UTC] tony at marston-home dot demon dot co dot uk
[2010-02-10 08:17 UTC] carsten_sttgt at gmx dot de
[2010-02-10 10:18 UTC] pajoye@php.net
[2010-02-10 10:57 UTC] tony at marston-home dot demon dot co dot uk
THIS IS NOT BOGUS, IT IS A GENUINE BUG!!! If print_r(gethostbynamel('localhost')); produces the following: Array ( [0] => 127.0.0.1 ) then why can't fsockopen connect to 'localhost'? It is a valid name which is recognised by every other piece of software on my computer, so there is no good reason why fsockopen should have a problem with it. I have another PC which runs 5.3.0 where fsockopen does not have a problem with 'localhost', therefore there is a bug in 5.2[2010-02-10 11:06 UTC] pajoye@php.net
[2010-02-10 11:27 UTC] tony at marston-home dot demon dot co dot uk
[2010-02-12 14:22 UTC] tony at marston-home dot demon dot co dot uk
[2010-09-07 10:27 UTC] cataphract@php.net
-Status: Bogus +Status: Assigned -Assigned To: +Assigned To: pajoye
[2010-09-07 10:54 UTC] cataphract@php.net
[2010-09-07 11:48 UTC] pajoye@php.net
-Status: Assigned +Status: Closed
[2010-09-07 11:48 UTC] pajoye@php.net
[2012-10-22 15:46 UTC] sp01 at 6vcommerce dot ca