php 服务器中的 curl“连接中的未知 SSL 协议错误”错误,但适用于本地

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20988782/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 03:43:54  来源:igfitidea点击:

curl "Unknown SSL protocol error in connection" error in server, but works on local

phpcurlssl

提问by martriay

I'm trying to retrieve data from a site (i've censored the url) with this code:

我正在尝试使用以下代码从站点检索数据(我已经了网址):

<?php 

  $url = [doesnt really matter];

  $ch = curl_init();

  curl_setopt($ch, CURLOPT_URL, $url);
  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

  $archivo_xml = fopen("test.tst", "w");

  curl_setopt($ch, CURLOPT_FILE,$archivo_xml);

  curl_exec($ch);
  $as1 = curl_getinfo($ch, CURLINFO_NAMELOOKUP_TIME);
  $as2 = curl_getinfo($ch, CURLINFO_CONNECT_TIME);
  $as3 = curl_getinfo($ch, CURLINFO_PRETRANSFER_TIME);
  $as4 = curl_getinfo($ch, CURLINFO_STARTTRANSFER_TIME);
  $as5 = curl_getinfo($ch, CURLINFO_TOTAL_TIME);

  echo "Lookup: ",$as1," \n\r Connect: ",$as2," \n\r Pretransfer: ",$as3," \n\r Starttransfer: ",$as4," \n\r Total: ",$as5,"\n\r","Error: ", curl_error($ch), "\n\r";

  curl_close($ch);
  fclose($archivo_xml);

?>

It work's fine on local but not in the server. Here's the output from local:

它在本地运行良好,但在服务器中运行不正常。这是本地的输出:

Lookup: 0.015155 
 Connect: 0.0281 
 Pretransfer: 0.129087 
 Starttransfer: 0.786341 
 Total: 0.786384
Error:

and here's the output from the server:

这是服务器的输出:

Lookup: 0.028731 
 Connect: 0.043182 
 Pretransfer: 0 
 Starttransfer: 0 
 Total: 60.057787
Error: Unknown SSL protocol error in connection to [censored url] 

With any other url works just fine, the problem is with this specific one.

任何其他网址都可以正常工作,问题出在这个特定的网址上。

localhost PHP version: 5.4.23

本地主机 PHP 版本:5.4.23

server PHP version: 5.5.7

服务器 PHP 版本:5.5.7

Thanks in advance

提前致谢

采纳答案by martriay

SOLVED. Because of this known bug http://sourceforge.net/p/curl/bugs/1319/I downgraded curl to 7.33 and it worked.

解决了。由于这个已知的错误http://sourceforge.net/p/curl/bugs/1319/我将 curl 降级到 7.33 并且它起作用了。

回答by Shankar Damodaran

Try setting cURLparam

尝试设置cURL参数

curl_setopt($ch, CURLOPT_SSLVERSION,3); // Apparently 2 or 3

回答by Chintan

As in the case of this post adding curl_setopt($ch, CURLOPT_SSLVERSION,3);did not immediately resolve the issue today the SSL has been re-validated and accepted.

就像这篇文章的情况一样,今天添加curl_setopt($ch, CURLOPT_SSLVERSION,3);并没有立即解决问题,SSL 已被重新验证并被接受。

回答by Ruud Laan

I had a similar situation with the same error. Using a constant like this made it work:

我有同样的错误的类似情况。使用这样的常量使其工作:

curl_setopt( $handle, CURLOPT_SSLVERSION, 'CURL_SSLVERSION_SSLv3' );

Researched link: https://github.com/guzzle/guzzle/issues/1364

研究链接:https: //github.com/guzzle/guzzle/issues/1364

Other constants: https://curl.haxx.se/libcurl/c/CURLOPT_SSLVERSION.html

其他常量:https: //curl.haxx.se/libcurl/c/CURLOPT_SSLVERSION.html

回答by kwelsan

Try with both options

尝试两个选项

curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

If still not working then URL might be blocked on your server.

如果仍然无法正常工作,则 URL 可能在您的服务器上被阻止。