Page 1 of 1

Cannot open any file using fopen() when specifying url.

PostPosted: 13. June 2008 05:07
by ssinghal66
I am trying to run a simple script such as:

$url='http://localhost/xampp/index.php';
//$url='c:\xampp\htdocs\index.php';
if (fopen ($url,"r"))
{
echo "It exists !!";
}
else
{
echo "It does not exist !!";
}

Error I get is :

[message] => fopen(http://localhost/xampp/index.php): 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.

If I replace the url with 'c:\xampp\htdocs\index.php' it works fine.

Please help. Already spent one whole day on this.

PostPosted: 13. June 2008 11:18
by Wiedmann
Try '127.0.0.1' instead of 'localhost' in the uri.

Thanks. That worked.

PostPosted: 13. June 2008 19:46
by ssinghal66
But why does the 'localhost' not get resolved to that ip address. Just a thought. Thanks again.

PostPosted: 13. June 2008 20:13
by Wiedmann
But why does the 'localhost' not get resolved to that ip address.

The problem is an other:
With "localhost" PHP want access the server with IPv6. But Apache don't understand IPv6. With "127.0.0.1" IPv4 is used.