PHP Error tip failed to open stream:http request failed! perfect solution _php Tips

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

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

But some still will have this warning message, want to use perfect solution still one step, still have to set php.ini inside 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 OK

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

Encounter this problem in the work, after the perfect solution, so share to everybody.
I batch crawl chemblink of the structure of the loop found that some of the pictures can not be displayed, and remote files exist.
A similar warning:readfile (http://www.jb51.net/logo.gif) [Function.readfile] appears when crawling remote files: Failed to open stream:http request failed! Such a warning message that I used to be
Copy Code code as follows:

Ob_start ();
ReadFile ("Yun_qi_img/logo.gif");
$img = Ob_get_contents ();
Ob_end_clean ();


So in the running will occur from time to time the above error, I have changed file_get_contents and other functions are useless, in the online lookup found that with the curl method to crawl can not be wrong

Now more popular Use curl
Copy Code code as follows:

<?php
$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;
?>

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.