php error failed to open stream: HTTP request failed! The perfect solution
- 2020-05-07 19:22:37
- OfStack
google or baidu1, many of these problems, the solution is to modify php.ini, allow_url_fopen to enable allow_url_fopen = On
Some people say that in php.ini, there are two options :allow_url_fopen =on(which means you can open a remote file through url), user_agent= "Take it out." Restart the server.
However, some of you will still have this warning message, and you still need to set php.ini user_agent, php user_agent is PHP by default, so we will change it to Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0) to simulate a browser
user_agent = "Mozilla / 4.0 (compatible; MSIE 6.0; Windows NT 5.0)"
I met this problem at work and solved it perfectly, so I would like to share with you.
I found that some pictures could not be displayed after the loop, and the remote files existed.
When fetching remote file to similar Warning: readfile (. / / www ofstack. com/logo. gif) [function. readfile] : failed to open stream: HTTP request failed! This is the warning message I used
In this way, the above errors will occur from time to time in the operation. I have also changed file_get_contents and other functions, which are not used. After looking up on the Internet, I found that the CURL method can not be used to grab errors
curl is more popular now
Some people say that in php.ini, there are two options :allow_url_fopen =on(which means you can open a remote file through url), user_agent= "Take it out." Restart the server.
However, some of you will still have this warning message, and you still need to set php.ini user_agent, php user_agent is PHP by default, so we will change it to Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0) to simulate a browser
user_agent = "Mozilla / 4.0 (compatible; MSIE 6.0; Windows NT 5.0)"
I met this problem at work and solved it perfectly, so I would like to share with you.
I found that some pictures could not be displayed after the loop, and the remote files existed.
When fetching remote file to similar Warning: readfile (. / / www ofstack. com/logo. gif) [function. readfile] : failed to open stream: HTTP request failed! This is the warning message I used
ob_start();
readfile("//www.ofstack.com/logo.gif");
$img = ob_get_contents();
ob_end_clean();
In this way, the above errors will occur from time to time in the operation. I have also changed file_get_contents and other functions, which are not used. After looking up on the Internet, I found that the CURL method can not be used to grab errors
curl is more popular now
<?php
$url = "http://s.ofstack.com";
$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;
?>