解决curl中sslv3 alert handshake failure

今天在php(版本:php54n,是程序自带的)中遇到个curl的问题,请求一个https的站,一直返回false,测试代码如下:

<?php
$ch = curl_init();
$url  = 'https://localhost';
curl_setopt_array($ch, array(
        CURLOPT_URL => $url,        
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_SSL_VERIFYPEER => false,
        CURLOPT_SSL_VERIFYHOST => false,
        CURLOPT_TIMEOUT => 30,
        CURLOPT_USERAGENT => 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.116 Safari/537.36'
    )
);
var_dump(curl_exec($ch));
var_dump(curl_errno($ch));
var_dump(curl_error($ch));

打印信息:

bool(false)
int(35)
string(80) “error:14077410:SSL routines:SSL23_GET_SERVER_HELLO:sslv3 alert handshake failure”

按照网上搜索到的消息都是类似:

curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_CIPHER_LIST, 'TLSv1');

但是代码中我已经禁止验证证书了,后来灵机一动,ssl一般都跟libeay32.dll,ssleay32.dll两个库文件有关,搜了下电脑里很多软件都自带这两个文件,就把QQ的复制到php目录中替换解决了。

没有评论: