• Warning:file_get_contents():SSL operation failed with code 1 狼人:


    今天使用PHP写程序获取指定接口的内容,获取内容为空加上报错报错提示显示SSL operation failed with code 1,接下来吾爱编程为大家介绍一下解决方法,有需要的小伙伴可以参考一下:

    1、错误提示:

    Warning:file_get_contents():SSL operation failed with code 1

    2、解决方法:

        (1)、方法一:

        这个时候我们需要使用到了file_get_contents的第三个参数,然后使用stream_context_create函数生成对应的资源流,参数代码如下:

    $stream_opts = [
                "ssl" => [
                    "verify_peer"=>false,
                    "verify_peer_name"=>false,
                ]
            ];
    $result = file_get_contents("https://www.itbiancheng.com", false, stream_context_create($stream_opts));

        (2)、方法二:

        直接在服务器上面安装证书根证书,命令如下:

    yum install ca-certificates
    Warning:file_get_contents():SSL operation failed with code 1

    PS:如果代码中多处用到了file_get_contents,建议使用第二种方法

    3、知识扩展:

        (1)、file_get_contents语法:

    file_get_contents(path,include_path,context,start,max_length)

        (2)、file_get_contents相关参数:

    Warning:file_get_contents():SSL operation failed with code 1

        (3)、stream_context_create相关:

        创建并返回一个资源流上下文,该资源流中包含了 options 中提前设定的所有参数的值。 

     stream_context_create ([ array $options [, array $params ]] ) : resource
         PS:options必须是一个二维关联数组,格式如下:$arr['wrapper']['option'] = $value 。默认是一个空数组 

    以上就是吾爱编程为大家介绍的关于file_get_contents错误的解决方法的全部内容了,希望对大家有所帮助,了解更多相关文章请关注吾爱编程网!

  • 相关阅读:
    mtr-网络分析工具
    vpc是什么
    openstack安全组
    nginx服务器有什么作用?什么叫反向代理?为什么要使用反向代理?
    rpm 命令详解
    跟踪路由
    网卡配置bond(绑定)
    核心交换机、汇聚交换机是什么
    U盘制作Linux镜像
    11.MySQL 慢日志PT分析 可视化
  • 原文地址:https://www.cnblogs.com/waw/p/16404624.html
Copyright © 2020-2023  润新知