I have experimented myself the chore of detecting the exact version of CURL used by my PHP code. This is especially true in the case of choosy protocol version code.
Which binary does PHP use?
We assume to use PHP from the command line (the CLI interface), later we will examine the case of PHP code inside a web page).
As a first step we determine the version of PHP we are using:
> php -v
PHP 7.0.4 (cli) (built: Mar 30 2016 14:47:23) ( NTS )
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies
(output of my machine).
Now note that the PHP curl extension does not contain the CURL code itself but it is only a bridge to the curl library already installed on our machine.
To have more info about PHP, type:
> php -i
(this will output a big chunk of text, put it in a file to better read it).
Put the attention on the configure section and you should see something like:
Configure Command => ...'--with-curl=/usr/local/opt/curl' ...
(I substituted ‘…’ to output irrelevant with our problem).
So the version of curl used by PHP is that in the folder ‘/usr/local/opt/curl’. The binary is in the subfolder ‘bin’, so we can check the version on that curl using:
> /usr/local/opt/curl/bin/curl --version
curl 7.47.1 (x86_64-apple-darwin14.5.0) libcurl/7.47.1 OpenSSL/1.0.2g zlib/1.2.5 nghttp2/1.8.0
Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtsp smb smbs smtp smtps telnet tftp
Features: IPv6 Largefile NTLM NTLM_WB SSL libz TLS-SRP HTTP2 UnixSockets
Note that this can be different from the result of
if we have more than one version of curl installed on the system (and in fact this is what sometimes drives developers, like me, crazy).
So I remark how it is important to get the version of the curl ‘used’ by PHP, not the version of a generic ‘curl’ command.
Check the PHP output directly
So the previous discussion is useful to understand what happens behind the scene to better debug versioning problems.
But in PHP we have a shortcut to know all this. In the previous result of command ‘php -i’, check the ‘curl’ section, something like:
cURL support => enabled
cURL Information => 7.47.1
Age => 3
AsynchDNS => No
CharConv => No
Debug => No
GSS-Negotiate => No
IDN => No
IPv6 => Yes
krb4 => No
Largefile => Yes
libz => Yes
NTLM => Yes
NTLMWB => Yes
SPNEGO => No
SSL => Yes
SSPI => No
TLS-SRP => Yes
HTTP2 => Yes
GSSAPI => No
Protocols => dict, file, ftp, ftps, gopher, http, https, imap, imaps, ldap, ldaps, pop3, pop3s, rtsp, smb, smbs, smtp, smtps, telnet, tftp
Host => x86_64-apple-darwin14.5.0
SSL Version => OpenSSL/1.0.2g
ZLib Version => 1.2.5
And from this we can directly know the exact version used by PHP.
PHP from a WEB page
After following the previous steps, we happily launch a PHP web page (served by Apache or another HTTP server) with our curl code and … surprise! We have completely different results, why?
If PHP runs as an Apache module (as usually, unless you run it as a CGI) the version of PHP can be different from that launched from the command line. And that version of PHP can use a different version of CURL!
In this case our tests on the command line are useless and we must repeat that “from the web”, that is, to get all the previous info “passing through” the PHP APACHE module.
We achieve this by writing a simple PHP page like the following:
and in the result html page check the same info we found in the ‘php -v’ and ‘php-i’ commands.
CURL binary used by PHP:
CURL PHP section:
A final note
We have seen how to exactly check the version of CURL used by PHP CLI and PHP Apache Module.
But what to do if this is not the version we want?
From the previous discussion it will be clear what to do then:
1 – install on your system a version of CURL suitable with your needs
2 – be sure that PHP uses that precise version of CURL
For the second point you can recompile PHP, but this is not trivial. Otherwise you can find distributions of PHP that search the curl library in canonical places of you system (for example I found very useful on OSX the homebrew installer).
Enjoy CURL and … good luck.