- Forums
- PHP
- File_get_contents "failed To Open Stream: Connection Timed Out"
This Page Contains information about File_get_contents "failed To Open Stream: Connection Timed Out" By wallpaperama in category PHP with 2 Replies. [1247], Last Updated: Sat May 18, 2024
wallpaperama
Mon Jan 26, 2009
2 Comments
7363 Visits
hi i tried your script:
<?php
ini_set('display_errors', 1);
$MyLink = 'example.com';
$CheckDoman = 'http://www.example.com/';
$i = file_get_contents($CheckDoman);
echo htmlspecialchars ($i);
if(strstr($i,$MyLink)){
echo $MyLink .' Was Found';
}else{
echo $MyLink .' Was NOT Found';
}
?>
but when i run the script i get this error:
Warning: file_get_contents(http://www.example.com/) [function.file-get-contents]: failed to open stream: Connection timed out in /var/www/example/test/get-HTML-from-url.php on line 6
wallpaperama.com Was NOT Found
i thot it was because i was behind a firewall. i checked my cisco pix firewall and it was ok, the firewall was not causing the problem. i thot it was because the firewall was configured to drop the Curl packets but i found out that it was not the case. so the next thing to troubleshoot was to find out if my configuration in PHP was doing anything to do with this error, then i ran a phpinfo(); and it showed CURL was enabled. so now that i know its not my php configuration, the next thing to check was maybe it was your script that was doing the problem. so i ran it on my developement machine where there is not firewall. and it worked!! so i keep thinking it was my firewall that was causing the problem. so what i did i installed lynx on my production server to make sure i can access port 80, so i installed lynx and i was able to go to http://www.google.com so know i know for sure its not the firewall, and its not the script, and its not the configureation of my php. so what else can it be..
well, the answer is simple. i was trying to run the script on my own website. lets say my website is example.com and i am also trying to get the file_get_contents() on my own domain. so when i changed it to another domain, for example lets say google.com i got the code. so i changed the domain to google.com and it worked, this is the code i used to fix it and make it work
<?php
ini_set('display_errors', 1);
$MyLink = 'example.com';
$CheckDoman = 'http://www.google.com/';
$i = file_get_contents($CheckDoman);
echo htmlspecialchars ($i);
if(strstr($i,$MyLink)){
echo $MyLink .' Was Found';
}else{
echo $MyLink .' Was NOT Found';
}
?>