|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #47437 fsockopen doesn't work with DNS names, only IPs
Submitted: 2009-02-18 14:55 UTC Modified: 2010-09-07 11:20 UTC
From: ogi at triangle dot bg Assigned: pajoye (profile)
Status: Duplicate Package: Sockets related
PHP Version: 5.2.9RC2 OS: Windows XP Pro SP3
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.
Block user comment
Status: Assign to:
Bug Type:
From: ogi at triangle dot bg
New email:
PHP Version: OS:


 [2009-02-18 14:55 UTC] ogi at triangle dot bg
Any DNS name passed to fsockopen is not recognized. Everything in the system works fine with DNS names - Firefox, nslookup command-line utility, DNS Client service is started. If it matters, PHP is installed as module in Apache 2.2.10.

Reproduce code:
var_dump(fsockopen(gethostbyname('localhost'), 80));
var_dump(fsockopen('localhost', 80));

Expected result:
resource(2) of type (stream)
resource(3) of type (stream)

Actual result:
resource(2) of type (stream)
Warning: fsockopen() [function.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:\Program Files\drupal\i.php on line 4


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2009-02-18 16:02 UTC]
Any hostname or only localhost?
 [2009-02-18 17:00 UTC] ogi at triangle dot bg
'localhost' and system host names (both short host name and FQDN) behave like already described. I've just found out that other host names that are not the local system work fine.
 [2009-02-18 17:03 UTC]
Can you check that you do not have IPv6 enabled (it is not in xp Pro afaict)? I think it is enabled and your host file should have a line like:

::1 locahost ..other hosts...

comment it out and be sure that the ipv4 aliases are in place.
 [2009-02-18 17:05 UTC] ogi at triangle dot bg
C:\WINDOWS\system32\drivers\etc\hosts contains       localhost

and other entries are irrelevant to this case.

This happened after some Drupal updates but I can't see how this can influence PHP itself - the above PHP example is isolated from Drupal framework.
 [2009-02-18 17:11 UTC]
what's about IPv6?
 [2009-02-18 17:12 UTC] ogi at triangle dot bg
Bingo! After uninstalling IPv6 everything works as expected.

I remember that I installed IPv6 for XP and after that I didn't used Drupal. Today I updated Drupal and fell into this problem.

I don't know if this is PHP problem or some underlining library (XP bug?).
 [2009-02-18 17:16 UTC]
no php bug, it tries to contact localhost which was certainly updated to IPv6 ::1, or the server was using IPv6 and not ipv4. In both cases it is not a bug. (bogus)
 [2010-09-07 11:19 UTC]
Fix and discussions will go now into the bug #50963.
 [2010-09-07 11:19 UTC]
-Status: Bogus +Status: Duplicate
 [2010-09-07 11:20 UTC]
Fix and discussions will go now into the bug #50953.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Jul 19 14:01:30 2024 UTC