failed to open stream: HTTP request failed!

2023-08-27 22:34 By "Powerless" 2693 0 1

近日突然在日志中发现报错:

......
[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

再次排查调用处,问题修复!

评 论

View in WeChat

Others Discussion

  • 初识七层、五层、四层网络协议
    Posted on 2021-04-09 16:52
  • Redis各种数据类型的使用场景举例分析【二】
    Posted on 2018-11-22 10:30
  • QPS、TPS、RT、吞吐量到底是什么
    Posted on 2020-02-02 01:15
  • 2018年云计算热词
    Posted on 2019-06-12 18:19
  • Linux工具 - NM目标文件格式分析
    Posted on 2019-04-24 10:29
  • ACID原则
    Posted on 2020-12-17 16:36
  • 前端知识体系精简-Css
    Posted on 2018-03-28 18:34
  • 浏览器访问网站经历的步骤-Html
    Posted on 2018-11-28 18:48