Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Missing some CURL constants in PHP

Tags:

php

curl

php-curl

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.

like image 678
boobiq Avatar asked Dec 18 '25 11:12

boobiq


1 Answers

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.

like image 69
Charlotte Dunois Avatar answered Dec 20 '25 01:12

Charlotte Dunois



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!