try {.
$content = file_get_contents('https://meridian.sparkes.zone/');
} catch (Exception $e) {
// Handle exception
}
echo $content;
使用 http 和 https 之类的链接,一切正常,但是当您输入子域时,一切都会中断。
我抓住:
file_get_contents(): SSL operation failed with code 1. OpenSSL Error messages:
error:14077410:SSL routines:SSL23_GET_SERVER_HELLO:sslv3 alert handshake failure
帕玛迪!1
try-catch
, 不会捕获异常file_get_contents
,因为它仅适用于定义throw new Класс
.因此,在您的情况下,这是冗余代码。
为了
try-catch
- 尽管如此,开始捕获错误file_get_contents
,您需要使用set_error_handler
错误抑制运算符@
(我不建议使用此运算符),然后比较是否为空,如果是,则返回throw new Класс
。更正如下: