在做項(xiàng)目時用 file_get_contents 來獲取數(shù)據(jù),php 報(bào)錯 PHP Warning: file_get_contents failed to open stream: no suitable wrapper could be found.
最后用了curl來獲取數(shù)據(jù)!
今天百度了一下!找到了解決辦法!先拷貝過來!
系統(tǒng):centos 6.5
在錯誤日志中,php報(bào)的錯誤是:
- 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
此警告說服務(wù)器阻止訪問遠(yuǎn)程文件,修改php.ini
把:
allow_url_fopen = Off
allow_url_include = Off
改成:
allow_url_fopen = On
allow_url_include = On
重啟php-fpm或者重啟web服務(wù)。
如果還是無法解決的話
windows下處理方法:
c:/windows/php.ini
extension=php_openssl.dll 把前的;去掉,重啟iis服務(wù)。
linux下處理方法:
/etc/php.ini
extension=php_openssl.dll 把前的;去掉,重啟apache服務(wù)。
如果上面問題沒能解決我的問題,我們可以如下測試。
- $context = stream_context_create(array('http'=>array('ignore_errors'=>true)));
- $contents = file_get_contents($url, FALSE, $context);
新聞熱點(diǎn)
疑難解答