Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

php

curl

ssl

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

server PHP version: 5.5.7

Thanks in advance

like image 954
martriay Avatar asked Jan 08 '14 06:01

martriay


People also ask

How do I fix cURL 35 SSL connect error?

The cURL error 35 can appear when the cURL function cannot connect to your website using SSL. Curl often uses a different set of certificates, shipped with PHP. There are several things that can cause this problem, in most cases updating both cURL and PHP to a newer version will resolve this issue.

Could not initiate SSL tls connection error 140770FC SSL routines SSL23_ get_ server_ hello Unknown protocol?

If you see an error like this: error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol , it could be due to you typing the hostname incorrectly or the hostname is not yet tabled in your DNS. You can verify that with a simple "host" or "nslookup".


2 Answers

Try setting cURL param

curl_setopt($ch, CURLOPT_SSLVERSION,3); // Apparently 2 or 3
like image 123
Shankar Narayana Damodaran Avatar answered Sep 20 '22 17:09

Shankar Narayana Damodaran


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

like image 28
martriay Avatar answered Sep 20 '22 17:09

martriay