$url = "https://monURL";
$orignal_parse = parse_url($url, PHP_URL_HOST);
$get = stream_context_create(array("ssl" => array("capture_peer_cert" => TRUE)));
$read = stream_socket_client("ssl://".$orignal_parse.":443", $errno, $errstr, 30, STREAM_CLIENT_CONNECT, $get);
$cert = stream_context_get_params($read);
$certinfo = openssl_x509_parse($cert['options']['ssl']['peer_certificate']);
$nowLess7Days= date(DATE_RFC2822,strtotime('+ 7 day'));
$valid_to = date(DATE_RFC2822,$certinfo['validTo_time_t']);
echo "Now less 7 days :".$nowLess7Days."\r\n";
echo "Valid To :".$valid_to."\r\n";
if( $valid_to < $nowLess7Days)
{
echo 'ALERT : certificat will be expired in less 7 days !!!!';
}
else
{
echo 'INFO : no Problem';
}