1

I am using the PHP code below to load the certificate properties of an SSL website:

$dnsname        = 'www.google.com';
$dnsport        = 443;
$stream     = stream_context_create (array("ssl" => array("capture_peer_cert" => true)));
$url        = stream_socket_client("ssl://".$dnsname.":".$dnsport, $errno, $errstr, $timeout, STREAM_CLIENT_CONNECT, $stream);
$content    = stream_context_get_params($url);

This all works fine when SSL is working OK. But in case no SSL connection can be opened the script results in a PHP warning:

stream_socket_client(): unable to connect to ssl://www.google.nl:443 (Kan geen verbinding maken omdat de doelcomputer de verbinding actief heeft geweigerd. ) in C:\inetpub\monitor\autotask\checkssl.php on line 44

How to prevent the warning? I need a "if" but don't know what to check for.. Please help

1 Answer 1

1

Suppress the warning using the @ operator and check the outcome yourself based on the return value:

$socket = @stream_socket_client(...);
if ($socket === false) {
    die("Socket error: $errstr");
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.