Which CURL version is PHP running?

php version

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:

(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:

(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:

(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:

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:

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:

php curl 2

CURL PHP section:

php curl

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.

  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  

Valerio Ferrucci

Valerio Ferrucci (valfer) develops software on Apple Macintosh since the 1990s until today for MacOS, OSX and, since some years, iOS. He is also a Web (PHP/MySQL/JS/CSS) and Android Developer.

More Posts - Website

Follow Me:
TwitterFacebookLinkedIn

Leave a Reply

Your email address will not be published. Required fields are marked *