file_get_contents(): SSL operation failed with code 1. OpenSSL Error message

小竣 日常收集1,505阅读模式


file_get_contents(): SSL operation failed with code 1. OpenSSL Error message

file_get_contents(): SSL operation failed with code 1. OpenSSL Error message



今天跑之前写的一个采集,提示错误:

file_get_contents(): SSL operation failed with code 1. OpenSSL Error message

以为是升级了PHP版本到从7.4换成7.0的原因,结果换回原来的7.4的也提示,顺便解决了一下。
在file_get_contents前面加个配置,忽略证书验证即可。主要这里是采集,没必要做证书校验。

调整后代码:

$option=array('ssl'=>array('verify_peer' => false,'verify_peer_name' => false));
$html = file_get_contents("https://www.baidu.com",false,stream_context_create($option));

weinxin
我的微信
我的微信
微信扫一扫