Skip to content


Wamp php fopen and fsockopen problem on vista

I have finally found a solution to a fopen/fsockopen problem I was having on Vista using Wampserver…I know it’s not ideal to be developing on Windoze, but it’s my work machine so don’t crucify me 🙂

I wanted to access a php file on my localhost using the following code:

$fp = fopen("http://localhost/test/export.php", "r");

but got a [function.fopen] php warning:

Warning: fopen(http://localhost/test/export.php) [function.fopen]: failed to open stream: 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:\wamp\www\test\export.php on line 11

I also tried adding “@” before the fopen, but still got the same php warnings

$fp = @fopen("http://localhost/test/export.php", "r");

So instead I tried fsockopen instead, but got another smiliar warning:

Warning: fsockopen() [function.fsockopen]: unable to connect to http://localhost/test/export.php (Unable to find the socket transport “http” – did you forget to enable it when you configured PHP?) in C:\wamp\www\test\export.php on line 11

Now for the solution:

I came across a solution which worked for me on the wampserver forum:

I think I just found the solution here: bugs.php.net

It seems by changing ‘localhost’ to ‘127.0.0.1’ it works!

So, changing the code to look like this actually works:

$fp = fopen("http://127.0.0.1/test/export.php", "r");

Strange, but true. Thanks to anarchitecton!!!

Tags: , , , .

2 Responses

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.

  1. THANK YOU!

    I’ve been fighting this problem for a while now.

  2. Stephen Blake said

    Cool – happy to help!

Some HTML is OK

(required)

(required, but never shared)

or, reply to this post via trackback.