一旦工作,那就要努力的干,聪明的干,快速的干——用省下来的时间干自己喜欢干的事情。!

php 使用fopen/readfile等函数时打开https类型的URL返回false的解决方案

php lampnick 2047℃ 0评论

php 使用fopen/readfile等函数时打开https类型的URL返回false,报如下错误

fopen(): SSL operation failed with code 1. OpenSSL Error messages:
error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed

意思是证书验证失败,此时我们可以设置fopen/readfile的最后一个$context参数将ssl认证关闭就可以解决了,关闭方法如下:

    $context = stream_context_create(
            [
                'ssl' => [
                    'verify_peer' => false,
                ]
            ]);
       fopen($url, 'rb', null, $context)
       readfile($url, null, $context);

至此,就可以成功访问https类型URL的内容了哦,当然为了安全你也可以通过设置ssl的证书来进行访问哦。
具体的设置方法请参考:
https://www.php.net/manual/en/context.ssl.php

转载请注明:MitNick » php 使用fopen/readfile等函数时打开https类型的URL返回false的解决方案

喜欢 (56)or分享 (0)
头像
发表我的评论
取消评论
表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址