在做項目時用 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);
新聞熱點
疑難解答