file_get_contents(http://www.example.com/): failed to open stream: HTTP request failed!HTTP/1.1 403 Forbidden
近日突然在日志中发现报错:
...... [2023-08-27T10:08:27+08:00][error] [2]file_get_contents(http://www.example.com/): failed to open stream: HTTP request failed!HTTP/1.1 403 Forbidden ......
这个错误一般主要由下面几个问题导致:
1、allow_url_fopen 值未设置为on
2、allow_url_include 值未设置为on
3、user_agent 未启用
随即查看机器配置如下:
[root@wzxaini9 /]# vim /usr/local/php/lib/php.ini ...... ;;;;;;;;;;;;;;;;;; ; Fopen wrappers ; ;;;;;;;;;;;;;;;;;; ; Whether to allow the treatment of URLs (like http:// or ftp://) as files. ; http://php.net/allow-url-fopen allow_url_fopen = Off ; Whether to allow include/require to open URLs (like http:// or ftp://) as files. ; http://php.net/allow-url-include allow_url_include = On ; Define the anonymous ftp password (your email address). PHP's default setting ; for this is empty. ; http://php.net/from ;from="john@doe.com" ; Define the User-Agent string. PHP's default setting for this is empty. ; http://php.net/user-agent ; user_agent="PHP" ......
第一条和第三条都符合,随即做出两处修改
1、allow_url_fopen 的值改为 On
2、移除 user_agent="PHP" 前的 ;
结果如下
[root@wzxaini9 /]# vim /usr/local/php/lib/php.ini ...... ;;;;;;;;;;;;;;;;;; ; Fopen wrappers ; ;;;;;;;;;;;;;;;;;; ; Whether to allow the treatment of URLs (like http:// or ftp://) as files. ; http://php.net/allow-url-fopen allow_url_fopen = On ; Whether to allow include/require to open URLs (like http:// or ftp://) as files. ; http://php.net/allow-url-include allow_url_include = On ; Define the anonymous ftp password (your email address). PHP's default setting ; for this is empty. ; http://php.net/from ;from="john@doe.com" ; Define the User-Agent string. PHP's default setting for this is empty. ; http://php.net/user-agent user_agent="PHP" ......
修改保存后重启PHP服务
[root@wzxaini9 /]# service php-fpm reload
再次排查调用处,问题修复!
登录后可发表评论