PHP error hint failed to open Stream:http request failed! Perfect Solution _php Tutorial

Source: Internet
Author: User
Tags php error
Google or Baidu, a lot of such problems, the solution is to modify the php.ini, the Allow_url_fopen to enable, change to Allow_url_fopen = On

This can solve some people's problems, it is said in PHP.ini, there are two options: Allow_url_fopen =on (indicating that the remote file can be opened via a URL), user_agent= "PHP" (indicating which script to access the network, the default is preceded by a ";" Remove. ) Restart the server.

But some will have this warning message, want to use the perfect solution is one step, but also to set the php.ini inside the user_agent,php default user_agent is PHP, we change it to mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0) to simulate the browser is available

User_agent= "mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0) "

In the work encountered this problem, after the perfect solution, so share to everyone.
I batch crawl Chemblink the structure of the discovery loop after some pictures can not be displayed, and remote files exist.
Crawling remote files appears similar to Warning:readfile (http://www.jb51.net/logo.gif) [Function.readfile]: Failed to open stream:http request failed! Such a warning message that I am using is
Copy CodeThe code is as follows:
Ob_start ();
ReadFile ("Http://www.jb51.net/logo.gif");
$img = Ob_get_contents ();
Ob_end_clean ();


In this way in the run will occasionally appear the above error, I also changed file_get_contents and other functions are useless, after online review found that using the curl method to crawl without error

Now more popular with curl
Copy CodeThe code is as follows:
$url = "Http://s.jb51.net";
$ch = Curl_init ();
curl_setopt ($ch, Curlopt_url, $url);
curl_setopt ($ch, Curlopt_returntransfer, 1);
curl_setopt ($ch, curlopt_connecttimeout,10);
$dxycontent = curl_exec ($ch);
Echo $dxycontent;
?>

http://www.bkjia.com/PHPjc/323600.html www.bkjia.com true http://www.bkjia.com/PHPjc/323600.html techarticle Google or Baidu, a lot of such problems, the solution is to modify the php.ini, the Allow_url_fopen to enable, change to Allow_url_fopen = On this can solve some people's problems ...

  • 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.