get_file_contents() does not work for localhost

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
keenlearner
Forum Commoner
Posts: 50
Joined: Sun Dec 03, 2006 7:19 am

get_file_contents() does not work for localhost

Post by keenlearner »

Hello, I have problem with file_get_contents() in my localhost.
When i try

Code: Select all

echo file_get_contents('http://localhost/index.php'); // it output error of 
Warning: file_get_contents(http://localhost/index.php) [function.file-get-contents]: 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:\www\Apache2\htdocs\test.php on line 2

// but when i try 
echo file_get_contents('http://www.google.com/') // it works
my http://localhost/index.php just content a string "<h1> It works</h1>"
Does anybody know why ? I thought my firewall is blocking the connection, so when I disabled my firewall, it still not working. Thanks for any of your help.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

As it says, "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."
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

Maybe your host file isn't setup correctly? Try it with an IP.
keenlearner
Forum Commoner
Posts: 50
Joined: Sun Dec 03, 2006 7:19 am

Post by keenlearner »

Thanks for the two prompt reply, I never realize that actually the solutions is so easy until i never thinking of trying that.
It works when the url is without http://localhost/
echo file_get_contents('index.php');
Thanks...so happy. :D
Post Reply