When i use file_get_contents with a url (http://example.com or other), it will return false with different context, user_agent, etc:
file_get_contents(http://example.com):failed to open stream: operation failed
However when we used file_get_contents() for a local file, it works. But it shows the above error when we try to access any file through http.
I tried the same using cURL and got the following error:
cURL Error (7): couldn't connect to host
According to some solutions on stackoverflow, we changed this setting in php.ini file:
ini_set('allow_url_fopen', 1);
I have also used snoopy library after including snoopy class.php
require "Snoopy/Snoopy.class.php";
$snoopy = new $Snoopy;
fetchtext("http://example.com");
$text = $snoopy->results;
it is also giving an empty response.
If I cURL or wget the same URL using terminal, it works perfectly. But it doesn't work in the PHP code when the file is not local (through HTTP).
Server details:
Debian GNU/Linux 7.6 (wheezy)
Apache/2.2.22 (Debian)
PHP 5.4.45-0+deb7u7