PHP5 fsockopen(localhost, ...) doesn't work in MS Windows Vista

Submitted by Eus
on February 2, 2009 - 8:44pm

I have a PHP script that uses `fsockopen(localhost, ...)' to open a socket connection to another server residing in the same machine. It works beautifully in GNU+Linux hosts but not in Windows Vista.

Narrowing down the problem by turning off the Windows' firewall, checking the server to be contacted, and reinstalling the PHP, I was quite sure that the problem laid somewhere in the Windows Vista itself.

Googling with keywords "fsockopen problem in vista" directly hit the answer:
http://bugs.php.net/44335 (PHP Bugs: #44335: fsockopen on localhost on Vista)

It seems that the improper way Windows Vista translates `localhost' to `127.0.0.1' confuses PHP 5.2.5, 5.2.1, 5.1.6, 5.0.3, but not 4.4.8.

The solution is simple. Either I do `fsockopen('127.0.0.1', ...)' or just fix the culprit by commenting out `::1' from `C:\windows\system32\drivers\etc\hosts'.

Well, it is simple but I spent four hours to get to the answer.

Moral of the story:
1. Always google for the answer first with the _right_ keyword. Yes, two hours into the problem, I googled for `fsockopen timeout in windows'. I found no answer because I didn't include the magical keyword: `vista'.

2. DON'T use Windows Vista, that bloated badly-configured OS (http://badvista.org). Use GNU+Linux and grasp your software freedom :-)

Glad to have found this blog as it saved me hours...

sanjeevC (not verified)
on
March 27, 2009 - 3:43am

Vista was driving me insane as I was at total loss on what was causing the Trac and Testlink integration to fail. Concur with your conclusion.
Thanks!

Glad that my experience can help somebody else

Eus
on
March 31, 2009 - 1:16am

Hi Ho!

You are welcome :-)

Best regards,
Eus (FSF member #4445)

In this digital era, where computing technology is pervasive,
your freedom depends on the software controlling those computing devices.

Join free software movement today!
It is free as in freedom, not as in free beer!

Join: http://www.fsf.org/jf?referrer=4445

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.