6

cURL stopped working. I started to get this error (it used work fine till few hours ago).

I am using cURL extension for PHP. I found some solution for curl command line, but unfortunately i do not understand them :/ and I do not know how to move them to PHP cURl flags.

cURL conf:

$curl=curl_init();
curl_setopt($curl, CURLOPT_URL, "https://pln.bitcurex.com/data/ticker.json");
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl, CURLOPT_SSLVERSION, 3);
curl_setopt($curl, CURLOPT_TIMEOUT, 10);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curl, CURLOPT_USERAGENT, $this->useragent);
curl_setopt($curl, CURLOPT_VERBOSE, 0);
curl_setopt($curl, CURLOPT_HEADER, FALSE);
curl_setopt($curl, CURLOPT_HTTPHEADER, $this->headers);

if(substr($url, 0, 5)=='https') curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 2);

if($this->ciastko)
{
    curl_setopt($curl, CURLOPT_COOKIEJAR, $this->ciastko);
    curl_setopt($curl, CURLOPT_COOKIEFILE, $this->ciastko);
}

if($this->post)
{
    if( is_array($this->post) && count($this->post) > 0 )
    {
        $postdata = http_build_query($this->post,'','&');
    }
    elseif( is_string($this->post) )
    {
        $postdata = $this->post;
    }
    else $postdata = '';

    curl_setopt($curl, CURLOPT_POST, 1);
    curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata);
}

$wynik=curl_exec($curl);

error:

35: error:14094410:SSL routines:SSL3_READ_BYTES:sslv3 alert handshake failure

any ideas how to fix this?

1

3 Answers 3

12

I just change from

curl_setopt($curl, CURLOPT_SSLVERSION, 3);

to

curl_setopt($curl, CURLOPT_SSLVERSION, 4);

11

I know it's a bit outdated problem, but I've got a solution for others:

curl_setopt($ch, CURLOPT_SSLVERSION, 3);
curl_setopt($ch, CURLOPT_SSL_CIPHER_LIST, 'SSLv3');
3
  • 1
    Can you please explain what these setting do and how it is related to curl error message asked about in the question?
    – hakre
    Jan 1, 2015 at 21:48
  • This is not working, and I am having the same issue... This seems to be happening on older Centos 5 based servers, with older OpenSSL 0.9.8 Feb 1, 2015 at 16:53
  • 4
    Due to the POODLE vulnerability many sites are now disabling SSL 3.0. You should switch to TLS, which would look like this: curl_setopt($ch, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1) Mar 5, 2015 at 22:01
0

Input values :

$params = Array
    (
        "username" => "XXXXXXXXXX",
        "password" => "XXXXXX"
    );

$path ='https://www.XXXXXXXX.com/xx/xxx/format/json/';

Function:

function curlpost($parameters, $path){
     $apiUrl = $path;
     $curl_handle = curl_init();
     curl_setopt($curl_handle, CURLOPT_URL, $apiUrl);
     curl_setopt($curl_handle, CURLOPT_BUFFERSIZE, 1024);
     curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, TRUE);
     curl_setopt($curl_handle, CURLOPT_SSL_VERIFYPEER, TRUE);
     curl_setopt($curl_handle, CURLOPT_SSL_VERIFYHOST, TRUE);
     curl_setopt($curl_handle, CURLOPT_POST, TRUE);
     curl_setopt($curl_handle, CURLOPT_PROXY, '');
     curl_setopt($curl_handle, CURLOPT_SSLVERSION, 4);
     curl_setopt($curl_handle, CURLOPT_POSTFIELDS, $parameters);
     $response = curl_exec($curl_handle);

     $content = curl_exec( $curl_handle );
     $err     = curl_errno( $curl_handle );
     $errmsg  = curl_error( $curl_handle );
     $header  = curl_getinfo( $curl_handle );
     curl_close( $curl_handle );

     $header['errno']   = $err;
     $header['errmsg']  = $errmsg;
     $header['content'] = $content;
    curl_close($curl_handle);
     return $header;
 } 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.