PHP Warning: file_get_contents failed to open stream solution

Source: Internet
Author: User
Tags ini wrapper

When using file_get_contents to retrieve data, php reports the following error: PHP Warning: file_get_contents failed to open stream: no suitable wrapper cocould be found.

Finally, curl is used to obtain data!

Baidu today! The solution is found! Copy it first!

System: centos 6.5

In the error log, the error reported by php is

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 cocould be found

This warning indicates that the server blocks access to remote files and modifies php. ini.

Set

Allow_url_fopen = Off
Allow_url_include = Off

Change

Allow_url_fopen = On
Allow_url_include = On

Restart php-fpm or the web service.

If the problem persists

Solution in windows:

C: \ windows \ php. ini

Extension = php_openssl.dll remove the previous one and restart the iis service.

Solution in linux:

/Etc/php. ini

Extension = php_openssl.dll remove the previous one and restart the apache service.


If the problem above does not solve my problem, we can test it as follows.


$ Context = stream_context_create (array ('http '=> array ('ignore _ errors' => true )));
$ Contents = file_get_contents ($ url, FALSE, $ context );

Ignore errors when requests are allowed. Can solve the warning information

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.