|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[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
Patchesconnect_fix_win32 (last revision 2010-09-07 08:26 UTC by cataphract@php.net)Pull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Oct 29 10:00:01 2025 UTC |
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