Home > Article > Backend Development > PHP error message failed to open stream: HTTP request failed! The perfect solution_PHP tutorial
Google or Baidu, there are many such problems, the solution is to modify php.ini, enable allow_url_fopen, change 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 (indicates that remote files can be opened through url), user_agent="PHP" (indicates which script is used to access the network, and there is a ";" in front of the default. Just remove it.) Restart server.
But some people still have this warning message. There is still one step left to achieve a perfect solution. You have to set the user_agent in php.ini. The default user_agent in php is PHP. We changed 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)”
Encountered at work This problem was finally solved perfectly, so I share it with everyone.
I grabbed the structural formula of chemblink in batches and found that some pictures could not be displayed after the loop, but the remote files existed.
When grabbing remote files, a warning message similar to Warning: readfile(http://www.jb51.net/logo.gif) [function.readfile]: failed to open stream: HTTP request failed! appeared. I The code used is