美文网首页PHP开发技巧
PHP SSL operation failed with co

PHP SSL operation failed with co

作者: 尤旭 | 来源:发表于2019-02-27 15:39 被阅读0次

    在使用例如file_get_contents这样的函数读取https的资源的时候,遇到这个报错信息
    首先确认加载了openssl模块 并且allow_url_fopen是打开状态
    这种时候有两种方案

    第一种 简单粗暴的跳过ssl认证

    <?php
    $arrContextOptions=array(
        "ssl"=>array(
            "verify_peer"=>false,
            "verify_peer_name"=>false,
        ),
    );  
    
    $response = file_get_contents("https://maps.co.weber.ut.us/arcgis/rest/services/SDE_composite_locator/GeocodeServer/findAddressCandidates?Street=&SingleLine=3042+N+1050+W&outFields=*&outSR=102100&searchExtent=&f=json", false, stream_context_create($arrContextOptions));
    
    echo $response; ?>
    

    第一种方法属于比较粗暴的方法 直接放弃ssl认证,不建议这种方法。

    第二种方法

    1.前往ca证书下载地址下载下来证书
    2.上传至服务器的php的可读目录
    3.配置php.ini 中的openssl.cafile

    [openssl]
    openssl.cafile=/***php可读目录***/cert.pem
    

    4.重启php-fpm就可以了。

    相关文章

      网友评论

        本文标题:PHP SSL operation failed with co

        本文链接:https://www.haomeiwen.com/subject/tfrfuqtx.html