相关疑难解决方法(0)

SSL错误SSL3_GET_SERVER_CERTIFICATE:证书验证失败

升级到PHP 5.6后,尝试连接到服务器时出错fsockopen()...

服务器(主机)上的证书是自签名的

PHP警告:fsockopen():SSL操作失败,代码为1. OpenSSL错误消息:错误:14090086:SSL例程:SSL3_GET_SERVER_CERTIFICATE:证书验证失败

if($fp = fsockopen($host, $port, $errno, $errstr, 20)){
    $this->request = 'POST '.substr($this->url, strlen($this->host)).' HTTP/1.1'.$crlf
        .'Host: '.$this->host.$crlf
        .'Content-Length: '.$content_length.$crlf
        .'Connection: Close'.$crlf.$crlf
        .$body;
    fwrite($fp, $this->request);

    while($line = fgets($fp)){
        if($line !== false){
            $this->response .= $line;
        }
    }

    fclose($fp);
}
Run Code Online (Sandbox Code Playgroud)

试过

# cd /etc/ssl/certs/
# wget http://curl.haxx.se/ca/cacert.pem
Run Code Online (Sandbox Code Playgroud)

php.ini中

openssl.cafile = "/etc/ssl/certs/cacert.pem"
Run Code Online (Sandbox Code Playgroud)

但脚本仍无法正常工作

更新

这有效

echo file_get_contents("/etc/ssl/certs/cacert.pem");
Run Code Online (Sandbox Code Playgroud)

更新2

$contextOptions = array(
    'ssl' => array(
        'verify_peer' => true, // You could skip all of the trouble by changing this …
Run Code Online (Sandbox Code Playgroud)

php apache openssl

43
推荐指数
3
解决办法
13万
查看次数

标签 统计

apache ×1

openssl ×1

php ×1