【发布时间】:2015-07-01 14:01:36
【问题描述】:
我有一些代码可以连接到公共网站并返回有关 SSL 证书的信息 - 代码运行良好。
我想添加一个 if 语句,如果无法建立连接,那么它将返回“无法建立连接”。现在,如果它无法连接,则会产生一大堆警告。
负责建立socket连接的代码如下
进行套接字连接
$ctx = stream_context_create( array("ssl" => $ssloptions) );
$result = stream_socket_client("ssl://$url:443", $errno, $errstr, 30, STREAM_CLIENT_CONNECT, $ctx);
$cont = stream_context_get_params($result);
如果套接字连接失败
echo "无法建立连接"
如果连接成功
foreach($cont["options"]["ssl"]["peer_certificate_chain"] as $cert) {
openssl_x509_export($cert, $pem_encoded);
echo $pem_encoded;
}
感谢您的帮助。
【问题讨论】:
-
你想使用 try / catch : php.net/manual/en/language.exceptions.php |--| php.net/manual/en/internals2.opcodes.catch.php
-
@MuppetGrinder,不太清楚如何应用它 - 感谢您的建议。
-
查看 [this][1] 上一个主题以了解如何在 php [1] 中使用 try / catch:stackoverflow.com/questions/9041173/…
标签: php