【发布时间】: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