因为测试域名比较多,而且强迫症就全加了免费的ssl,时间长了经常忘记,导致有的时候访问出错,所以就想着做个检测验证,刚好在网上也找到了,就记录一下
工作流程
- 添加域名列表
- 添加定时器,访问检测链接
- 检测链接,邮箱通知错误域名
检测ssl方法
function get_cert_info($domain){
$context = stream_context_create(['ssl' => [
'capture_peer_cert' => true,
'capture_peer_cert_chain' => true,
],
]);
$client = stream_socket_client("ssl://".$domain.":443", $errno, $errstr, 30, STREAM_CLIENT_CONNECT, $context);
if($client==false) {
return false;
}
$params = stream_context_get_params($client);
$cert = $params['options']['ssl']['peer_certificate'];
$cert_info = openssl_x509_parse($cert);
return $cert_info;
}
调用方法
$domain = 'www.baidu.com';
$cert_info = get_cert_info($domain);
$validTo_time_t = $cert_info['validTo_time_t'];
$validTo_time_d = date('Y-m-d H:i:s', $validTo_time_t);
echo($validTo_time_d);
评论 (0)