file_get_contents failed to open stream 解决报错问题的办法

2022-11-05php编程
917

file_get_contents函数在获得远程文件时提示Warning: file_get_contents failed to open stream,希望例子能够帮助到各位,希望例子能够帮助到大家。
在做项目时用 file_get_contents 来获取数据,php 报错  PHP Warning: file_get_contents failed to open stream: no suitable wrapper could be found.
最后用了curl来获取数据!

系统:centos 6.5
在错误日志中,php报的错误是:
Warning: file_get_contents() [function.file-get-contents]: http:// wrapper is disabled in the server configuration by allow_url_fopen=0
failed to open stream: no suitable wrapper could be found

此警告说服务器阻止访问远程文件,修改php.ini,把
​​​
allow_url_fopen = Off
allow_url_include = Off
改成
allow_url_fopen = On
allow_url_include = On
重启php-fpm或者重启web服务。
如果还是无法解决的话windows下处理方法:
c:\windows\php.ini
extension=php_openssl.dll 把前的;去掉,重启iis服务。

linux下处理方法:
/etc/php.ini
extension=php_openssl.dll 把前的;去掉,重启apache服务。

如果上面问题没能解决我的问题,我们可以如下测试。
$context = stream_context_create(array('http'=>array('ignore_errors'=>true)));
$contents = file_get_contents($url, FALSE, $context);

可以请求时,忽略错误。可以解决警告信息
The End
led led设备 file_get_contents

相关推荐

php中URL转发使用方法详解
这篇文章给大家分享的是PHP中的URL转发的使用方法,相信大部分人都还没学会这个技能,为了让大家更加了解,给大家总结了以下内容,话不多说,一起往下看吧。 1、使用函数file_get_contents()将URL传入,该函数会将URL中的网页源代码进行获取,然后将源代码输...
2023-06-06 php编程
269

PHP中file_get_contents函数抓取https地址出错的解决方法
方法一: 在php中,抓取https的网站,提示如下的错误内容: Warning: file_get_contents() [function.file-get-contents]: failed to open stream: Invalid argument in I:Webmyphpa.php on line 16 打开php.ini文件找到 ;extension=php_openssl.dll ,去掉...
2022-11-05 php编程
467

file_get_contents failed to open stream 解决报错问题的办法
file_get_contents函数在获得远程文件时提示Warning: file_get_contents failed to open stream,希望例子能够帮助到各位,希望例子能够帮助到大家。 在做项目时用 file_get_contents 来获取数据,php 报错 PHP Warning: file_get_contents failed to open st...
2022-11-05 php编程
917