I am writing a script which works similar as a bot and I try to parse out certain data from an url. I'm doing the "main" request with curl and a Dom Element for parsing the webpage, however I didnt find a solution to check if the site has a valid ssl certificate with Curl as well. Instead I'm doing it with fopen like this:
$stream = stream_context_create (array("ssl" => array("capture_peer_cert" => true)));
$read = fopen($url, "rb", false, $stream);
$cont = stream_context_get_params($read);
$var = ($cont["options"]["ssl"]["peer_certificate"]);
$result = (!is_null($var)) ? true : false;
if($result == true){
$returnData["ssl"] = 1; // index 7
} else {
$returnData["ssl"] = 0; // index 7
}
Now sometimes the fopen won't work correctly and return the following error:
fopen(http://): failed to open stream: operation failed
So I either want to check if the Site uses a SSL with curl or atleast return an empty string when this error occurs and then continue with the rest of the script because the data needs to be sent back to ajax at the end of the script. If not - Ajax will fail and I get a 504 back, because the script is running for too long.