3

I am trying to use constant CURL_SSLVERSION_TLSv1_2 in PHP, but I get error that such constant doesn't exist.

I checked PHP manual (http://php.net/manual/en/curl.constants.php) and it says that constant is Available since PHP 5.5.19 and 5.6.3

This is output of PHP/cURL versions on my local machine, where constant works fine

$ php -v                                                                                  
PHP 5.6.17-4+deb.sury.org~trusty+1 (cli)                                                               

$ php -i | grep -i curl                                                                   
Additional .ini files parsed => /etc/php/5.6/cli/conf.d/20-curl.ini,                                   
curl                                                                                                   
cURL support => enabled                                                                                
cURL Information => 7.35.0                                                                             

$ php -r var_dump(defined('CURL_SSLVERSION_TLSv1_2')); var_dump(CURL_SSLVERSION_TLSv1_2);
bool(true)                                                                                             
int(6)                                                                                                 

And on server where I'm trying to run that script, it's like this:

$ php -v
PHP 5.6.18 (cli) (built: Feb  4 2016 09:31:59)

$ php -i | grep -i curl
/etc/php.d/20-curl.ini,
curl
cURL support => enabled
cURL Information => 7.19.7

$ php -r "var_dump(defined('CURL_SSLVERSION_TLSv1_2')); var_dump(CURL_SSLVERSION_TLSv1_2);"
bool(false)
PHP Notice:  Use of undefined constant CURL_SSLVERSION_TLSv1_2 - assumed 'CURL_SSLVERSION_TLSv1_2' in Command line code on line 1
string(23) "CURL_SSLVERSION_TLSv1_2"

As you can see, I have PHP 5.6.8, which should have that constant according to PHP manual, but cURL extension is older than on my local.

Could it be the reason of missing constant? Can I update cURL extension for PHP? or is there any other reason why it could be missing?

Other, older constants, as CURL_SSLVERSION_TLSv1 are present just fine on both servers.

boobiq
  • 2,984
  • 2
  • 20
  • 27
  • 1
    Check OpenSSL version (1.0.1 is at least required for TLS v1.2). – Charlotte Dunois Mar 17 '16 at 19:39
  • 1
    The constant `CURL_SSLVERSION_TLSv1_2` was added in 7.34.0 of cURL. https://curl.haxx.se/libcurl/c/CURLOPT_SSLVERSION.html Check if you can upgrade through regular repository update. – Charlotte Dunois Mar 17 '16 at 19:40
  • Thanks, this is the issue, on our server we can't upgrade curl from official repositories so we need to wait for an update, but we ended up using "6" which is that constant's value.. if you add this as an answer, I will accept it :) – boobiq Mar 24 '16 at 08:19

1 Answers1

2

The constant CURL_SSLVERSION_TLSv1_2 was added in 7.34.0 of cURL. https://curl.haxx.se/libcurl/c/CURLOPT_SSLVERSION.html Check if you can upgrade through regular repository update (or use 6 as this is the constant's value).

As well OpenSSL 1.0.1 or higher is required to be able to use TLS1v2.

Charlotte Dunois
  • 4,638
  • 2
  • 20
  • 39