使用 get_headers 函数获取请求头时,报了下面的错。
get_headers(): SSL operation failed with code 1. OpenSSL Error messages:
error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in
这是因为你访问的URL没有有效的ssl证书
That error occurs when you’re trying to access a URL without a valid SSL certificate. You can work around this by overriding the default stream context, which will affect all subsequent file operations (including remote URLs)
解决办法
在get_headers前增加下面的代码
stream_context_set_default( [
'ssl' => [
'verify_peer' => false,
'verify_peer_name' => false,
],
]);
$headers = get_headers($httpPath, 1);