【问题标题】:get_headers Connection time outget_headers 连接超时
【发布时间】:2016-09-13 17:09:14
【问题描述】:

我收到此错误消息:get_headers failed to open stream: Connection timeout

代码如下:

$file_headers = @get_headers('http://www.example.fr');
print_r(get_headers('http://www.example.fr'));

if ( strpos( $file_headers[0], "200" )) {
    echo 'done';
} else {
    echo 'error';
}   

【问题讨论】:

    标签: php timeout get-headers


    【解决方案1】:

    将此设置为 120 秒超时(默认 - 60):

    ini_set('default_socket_timeout', 120);
    

    【讨论】:

      【解决方案2】:

      程序无法在时间限制内打开流 - 系统默认值,通常为 60 秒。检查文件是否存在并且可读。请注意,您第二次调用 get_headers(在 print 语句中),而 file_headers 流仍处于活动状态。

      【讨论】:

      • 没看明白,能解释一下吗谢谢
      • 你有什么不明白的?
      • 这句话请注意,您第二次调用 get_headers(在 print 语句中),而 file_headers 流仍处于活动状态。
      • 您调用一次 get_headers 来设置 file_headers 我相信这会打开流。在下一个语句 print_r 中,您再次调用 get_headers。我相信错误消息告诉您它无法再次打开该文件。
      猜你喜欢
      • 2022-01-21
      • 2011-08-28
      • 1970-01-01
      • 1970-01-01
      • 2018-07-24
      • 2013-09-03
      • 2011-08-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多