2012-06-06 79 views
1

我写了一个类,它通过php stream_socket_client检查ssl的证书。php stream_socket_client超时不按预期工作

但是,某些站点超时不起作用。这些脚本有时候会等待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; 
    }  

回答