When you use the file_get_contents method that comes with php5 to obtain remote files, sometimes file_get_contents (): failed to open stream: HTTP request failed will appear! This warning message.
Google or baidu, there are many such problems. The solution is to modify php. ini, enable allow_url_fopen, and change it to allow_url_fopen = On.
This can solve some people's problems, some people say that in php. in ini, there are two options: allow_url_fopen = on (indicating that remote files can be opened through url), user_agent = "PHP" (indicating which script is used to access the network. By default, there is "; "Remove it .) Restart the server.
However, some of them still have this warning message. If you want to use the perfect solution, you still have to set php. user_agent in ini. The default user_agent in php is PHP. We can change it to Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0) to simulate the browser.
User_agent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0 )"
If you encounter this problem at work and solve it perfectly, share it with you.
I captured the structure of chemblink in batches and found that some images cannot be displayed after the loop, while remote files exist.
The following error occurs when capturing remote files: Warning: readfile (http://www.bkjia.com/logo.gif) [function. readfile]: failed to open stream: HTTP request failed! Which of the following warning information is used?
Ob_start ();
Readfile ("http://www.bkjia.com/logo.gif ");
$ Img = ob_get_contents ();
Ob_end_clean ();
In this way, the above errors may occur from time to time during running, and I have changed file_get_contents and other functions, which are useless. After checking them online, I found that the CURL method will not cause errors.
$ Url = "http://www.bkjia.com/logo.gif ";
$ Ch = curl_init ();
Curl_setopt ($ ch, CURLOPT_URL, $ url );
Curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, 1 );
Curl_setopt ($ ch, CURLOPT_CONNECTTIMEOUT, 10 );
$ Img = curl_exec ($ ch );