升级到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)
$contextOptions = array(
'ssl' => array(
'verify_peer' => true, // You could skip all of the trouble by changing this …Run Code Online (Sandbox Code Playgroud)