SSL 证书监控 作者: Hogwarts 发布于: 2023-04-27 更新于: 2023-04-27 分类: 默认分类 域名多了,证书及时续签有时就会不及时。 acme.sh申请的证书是90天有效期,60天就自动申请,挺烦人的。因为acme.sh申请程序和域名工作不在同一主机上。要是弄个syncthing就好了。 这个页面挺好,仅需修改 `siteArray` 的网址即可。 需搭建LNMP环境,将Nginx的目录指向以下代码存放的index.php页面中。输入域名即可访问。 SSL 证书监控 网站 是否有效 到期时间 剩余时间 ["capture_peer_cert" => true], 'http' => [ 'method' => 'GET', 'user_agent' => 'Chrome 42.0.2311.135', 'timeout'=>500 ] ]); date_default_timezone_set('PRC'); $siteArray=array("https://009898.xyz","https://status.009898.xyz","https://cloud.009898.xyz","https://pic.009898.xyz","https://github.009898.xyz","https://jp.009898.xyz","https://sj.009898.xyz","https://nl.009898.xyz","https://hostcli.009898.xyz","https://imgcdn.009898.xyz"); foreach ($siteArray as $value){ //$r = fopen($value, "rb", false, $g); $orignal_parse = parse_url($value, PHP_URL_HOST); $r = stream_socket_client("ssl://".$orignal_parse.":443", $errno, $errstr, 30, STREAM_CLIENT_CONNECT, $g); $cont = stream_context_get_params($r); $cert = openssl_x509_parse($cont["options"]["ssl"]["peer_certificate"]); $expireDate = date("Y-m-d H:i:s", $cert['validTo_time_t']); $date1 = date_create(date('Y-m-d H:i:s')); $date2 = date_create($expireDate); $diff = date_diff($date1, $date2)->format('%R%a 天'); if(empty($cert['validTo_time_t'])) { echo "", str_replace("https://","",$value,$i), "", "已过期", "", $diff ,""; } else { echo "", str_replace("https://","",$value,$i), "", $expireDate , "", $diff ,""; } } ?> **请自行审视修改以上代码。** **参考:**[SSL 证书监控 php](https://009898.xyz/post/ssl-zheng-shu-jian-kong-php/ "SSL 证书监控 php") [一段php小代码,监控SSL证书过期问题](https://cloud.tencent.com/developer/article/1116498 "一段php小代码,监控SSL证书过期问题") 标签: PHP, ssl