【问题标题】:php stream_socket_client timeout does not work as expectedphp stream_socket_client 超时未按预期工作
【发布时间】:2012-07-19 22:52:56
【问题描述】:

我编写了一个类,它通过 php stream_socket_client 检查 ssl 验证。

但是超时不适用于某些网站。脚本有时会等待长达 60 秒以等待某些主机的响应(似乎是 php 配置限制)。

这很令人困惑,因为我将(连接)超时设置为 2 秒。对于 ssl 传输,我看不到任何其他限制,我可以设置以减少最大连接时间/传输时间。我可以使用其他时间限制吗?

    $options = array( 
        "ssl" => array(
        "capture_peer_cert"       => true,
        "capture_peer_chain"      => true,
        "capture_peer_cert_chain" => true, 
        "verify_peer"             => $verify_peer,  
        "allow_self_signed"       => $allow_self_signed )
    );

    if (strlen($this->cafile) > 0) {
        $options['ssl']['cafile'] = $this->cafile;
        if (strlen($this->capath) > 0 && [..]) {
            $options['ssl']['capath'] = $this->capath;
        }
    } else {
        $options['verify_peer'] = false;
    }

    $get = @stream_context_create( $options);

    $read = @stream_socket_client("ssl://$host:443", $errno, $errstr, 2, STREAM_CLIENT_CONNECT, $get);

    if($read){
        stream_set_timeout($read, 2);
        $cert = stream_context_get_params($read);
    } else {
        $cert = false;
    }       

【问题讨论】:

    标签: php stream-socket-client time-limiting


    【解决方案1】:

    查看http://php.net/manual/en/function.stream-set-timeout.php 以获取 Dianoga (dianoga7 [at] 3dgo.net) 回复。

    【讨论】:

      猜你喜欢
      • 2017-04-23
      • 2015-12-17
      • 1970-01-01
      • 2022-01-23
      • 2018-02-06
      • 2013-06-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多