zoukankan      html  css  js  c++  java
  • PHP Socket编程 之 fsockopen链接https时OpenSSL错误

    fsockopen()函数链接https时提示OpenSSL错误, 如下:

    1. fsockopen(): SSL operation failed with code 1. OpenSSL Error messages:
    2. error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed

    OpenSSL Error messages:error:14090086
    SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed 
    Failed to enable crypto

    此问题和php版本以及openssl相关

    一般是openssl根证书的问题

    php.ini相关设置
    allow_url_fopen = On
    allow_url_include = On
    openssl.cafile= /www/wdlinux/nginx/conf/cert/cacert.pem  (后来下载OPENSSL证书放上的)

    主要是因为php在5.6版本(包含5.6)以后的所有版本中如使用fsockopen() 或file_get_content()函数获取https站点的信息,OPENSSL会验证对方站点的SSL证书颁发机构是否可信,如果没有下载openssl根证书并在php.ini中设置openssl根证书路径,就会造成无法验证对方网站SSL证书是否可信,就无法使用上述两个函数获取到内容同时生成PHP警告信息,php5.6以前的老版本中此验证功能是没有开启或者说是没有作用的。所以php5.6以前的版本不存在此问题!

    ————————————————

    环境

    OS:Windows
    PHP Version:5.6.31

    问题

    error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed
    file_get_contents(): Failed to enable crypto

    解决方法
    从这儿下载 http://curl.haxx.se/ca/cacert.pem 存储为 cacert.crt
    打开 php.ini 找到里面的 curl.cainfo 和 openssl.cafile(2个 section 挨着的)
    修改 curl.cainfo=”c:certscacert.crt”
    修改 openssl.cafile=”c:pathcertscacert.crt”
    重启 IIS 服务(别忘记了)
    ————————————————https://blog.csdn.net/enlangs/article/details/78988673

    *用openssl_get_cert_locations() 函数列出 openssl证书的信息

    1. 查看证书信息,随便写一个php页面运行

    <?php echo '<pre>';

    print_r(openssl_get_cert_locations());

    显示:

    Array
    (
    [default_cert_file] => /apache24/conf/cert.pem
    [default_cert_file_env] => SSL_CERT_FILE
    [default_cert_dir] => /apache24/conf/certs
    [default_cert_dir_env] => SSL_CERT_DIR
    [default_private_dir] => /apache24/conf/private
    [default_default_cert_area] => /apache24/conf
    [ini_cafile] =>
    [ini_capath] =>
    )
    第一个default_cert_file根据你自己的位置查找,肯定找不到这个cert.pem文件

    2. 下载pem文件

    http://curl.haxx.se/docs/caextract.html

    到上一部显示的位置,重命名为  cert.pem

    3. 修改php.ini,根据你自己的系统变一下路径

    curl.cainfo = "E:/Program Files/apache24/conf/cert.pem"

    openssl.cafile = "E:/Program Files/apache24/conf/cert.pem"

    重启

  • 相关阅读:
    每天一篇经济学人 2020-09-15 分享在 特朗普的“疫苗政治”:科学与政治之争 | 经济学人
    english notes
    new word
    gilbert strang
    news etc
    对自己的要求
    JDBC添加数据
    题目-1031-字符串反转
    题目-1002-字符串分类统计
    ERROR:格式化hdfs后,datanode只启动了一个
  • 原文地址:https://www.cnblogs.com/7qin/p/13299024.html
Copyright © 2011-2022 走看看