使用 file_get_contents()方法来获取远程文件的时候,有时候会出现file_get_contents():
failed to open stream: HTTP request failed!这个警告信息。
Severity: Warning
Message: file_get_contents(http://geetest.com:8000/select?gid=bf59a3fe652ece81dfb179219ce5b46e&date=2013-08-09) [function.file-get-contents]:
failed to open stream: HTTP request failed! Internal Server Error
一种解决:
当使用php5自带的file_get_contents方法来获取远程文件的时候,有时候会出现file_get_contents():
设置php.ini里面的user_agent,php默认的user_agent是PHP,我们把它改成Mozilla/4.0 将user_agent=“PHP”
修改为 user_agent="Mozilla/4.0
在用file_get_contents函数采集网站时,有时会遇到明明用浏览器可以看,但就是采不到内容的问题。这很有可能是服务器上做了设置,根据 |
但是这种解决方案没能解决我的问题,我发现我还报了个错 Internal Server Error(内部服务器错误服务器遇到内部错误或配置错误,并无法完成您的请求)。
即是服务器端可以访问,但是服务器断有问题。
$context = stream_context_create(array('http'=>array('ignore_errors'=>true)));
$contents = file_get_contents($url, FALSE, $context);
可以请求时,忽略错误。可以解决警告信息