如何调试或修复cURL errno 35

时间:2015-02-09 20:57:23

标签: php curl

我正在尝试用PHP将cURL请求发送到URL。无论我尝试什么,我总是得到cURL errno 35(对于特定的URI)。卷曲文档有以下说法:

  

你真的想要错误缓冲区并在那里读取消息,因为它会稍微查明问题。可以是证书(文件格式,路径,权限),密码等。

然而,当试图捕获这些信息时,似乎没有返回任何内容。

$client = curl_init('https://dev.kelunik.com/css/all.min.css')

$log = fopen('/srv/www/Requestable/data/curl-log.txt', 'a+');

curl_setopt($client, CURLOPT_VERBOSE, 1);
curl_setopt($client, CURLOPT_STDERR, $log);
curl_setopt($client, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($client, CURLOPT_SSL_VERIFYHOST, 2)
curl_setopt($client, CURLOPT_CAINFO, __DIR__ . '/../../../../data/default.pem');
curl_setopt($client, CURLOPT_FAILONERROR, false);
curl_setopt($client, CURLOPT_RETURNTRANSFER, true);
curl_setopt($client, CURLOPT_HEADER, true);
curl_setopt($client, CURLINFO_HEADER_OUT, true);
curl_setopt($client, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($client, CURLOPT_CUSTOMREQUEST, 'GET');
curl_setopt($client, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);

if (!$response = curl_exec($client)) {
    throw new CurlException('Making request failed: ' . curl_error($client) . '(' . curl_errno($client) . ')');
}

fclose($log);

上面的代码总是抛出CurlException与errno 35,但是定义的日志文件保持为空。

尝试a different URI(使用来自同一CA的证书)时,它就可以正常工作了。我还检查了我的根CA捆绑,这是相当up2date:

  

Mozilla的证书数据下载日期:Wed Sep 3 03:12:03 2014

我还可以检查哪些具体内容导致错误?

注意:可以从浏览器以及本地开发环境中请求URI

注意2:我也尝试过,但没有手动设置导致相同错误的自定义CA根捆绑包。

OpenSSL版本:

Installed Packages
Name        : openssl
Arch        : x86_64
Version     : 1.0.1e
Release     : 30.el6_6.5

cURL版本:

curl 7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.16.2.3 Basic ECC zlib/1.2.3 libidn/1.18 libssh2/1.4.2
Protocols: tftp ftp telnet dict ldap ldaps http file https ftps scp sftp
Features: GSS-Negotiate IDN IPv6 Largefile NTLM SSL libz

2 个答案:

答案 0 :(得分:22)

问题与您的证书链无关,它是dev.kelunik.com的服务器配置。服务器仅接受ECDHE密码(ssllabs)。另一台服务器接受更广泛的密码。 (ssllabs)。虽然您的OpenSSL支持ECDHE,但您使用的cURL版本是使用NSS编译的,但并非如此。

您可以将输出与

进行比较
curl https://dev.kelunik.com

openssl s_client -connect dev.kelunik.com:443 -servername dev.kelunik.com 

您在这里有两个解决方案而不更改您的发行版。如果您可以访问其他服务器的配置,则可以更改SSL密码以使用DHE / RSA密码。确切的密码列表将取决于服务器配置 - ssllabs在该主题上有一个很好的blog post

否则,您需要针对OpenSSL重新编译cURL以访问所有可用的密码。 http://curl.haxx.se/docs/install.html提供了基本说明。

答案 1 :(得分:-1)

我将您的代码放在test.php文件中并在命令行上运行它 php test.php,它运行正常(打印"完成"在命令行上)。

以下是test.php的内容(代码中的细微修改)。我的php有Zend Engine v2.4.0版,它运行在Ubuntu 12.04上。

<?php>
$client = curl_init('https://dev.kelunik.com/css/all.min.css');
$log = fopen('/tmp/curl-log.txt', 'a+');

curl_setopt($client, CURLOPT_VERBOSE, 1);
curl_setopt($client, CURLOPT_STDERR, $log);
curl_setopt($client, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($client, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($client, CURLOPT_CAINFO, "/etc/ssl/certs/ssl-cert-snakeoil.pem");
curl_setopt($client, CURLOPT_FAILONERROR, false);
curl_setopt($client, CURLOPT_RETURNTRANSFER, true);
curl_setopt($client, CURLOPT_HEADER, true);
curl_setopt($client, CURLINFO_HEADER_OUT, true);
curl_setopt($client, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($client, CURLOPT_CUSTOMREQUEST, 'GET');
curl_setopt($client, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);

if (!$response = curl_exec($client)) {
    throw new CurlException('Making request failed: ' . curl_error($client) . '(' . curl_errno($client) . ')');
} else {
    echo "done!\n";
}

fclose($log);
?>