Reputation: 137
I tried to parse a website's html using file_get_contents().
I ran the code from my website.
It worked fine at first.But suddenly this error appeared:
Warning: file_get_contents(http://www.***.com/) [function.file-get-contents]: failed to open stream: HTTP request failed!
I tried other websites and it works fine.I ran the code from my other website and it works fine.
So I searched here and used the cURL code:
$curl_handle=curl_init();
curl_setopt($curl_handle, CURLOPT_URL,'http://www.***.com/');
curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 2);
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl_handle, CURLOPT_USERAGENT, 'Your application name');
$query = curl_exec($curl_handle);
curl_close($curl_handle);
But it just returns a blank page.
Looks like the website I tried to get contents blocked or blacklisted my website domain or something.
Do I have a way out of this ??
Upvotes: 1
Views: 903
Reputation: 84
your server cannot get to the other server
possibly dns issues, misspelling or the other server has blocked your ip..
what does curl_error() says?
BTW, CURLOPT_CONNECTTIMEOUT 2 seconds is usually quite small
Upvotes: 1
Reputation: 57709
You could try to figure out why your connection is being blocked:
Upvotes: 3