19

I installed the MongoDB PHP driver on my Linux machine a few months ago. Now, I want to know which version of the driver I installed. How can I find this information?

1

4 Answers 4

48

Legacy PECL Extension

The easiest way on the command line is by invoking reflection info:

$ php --ri mongo | grep Version

will output for example:

Version => 1.4.4

This will run ReflectionExtension::info() on the mongo extension, and grep the Version column.

Couple of other alternatives would be to execute some code, and print out the version information.

The MongoClient class (and the Mongo class for old extensions) as a VERSION constant:

$ php -r 'echo MongoClient::VERSION, "\n";'

will output (for example):

1.4.4

Or you could use the phpversion function to retrieve the version number from the module initialization:

$ php -r 'echo phpversion("mongo"), "\n";'

will output (for example):

1.4.4

EDIT - New Extension:

The above refers to the now-old and legacy pecl/mongo extension. There is a new extension called pecl/mongodb.

Similar commands work for the new extension:

$ php --ri mongodb | grep version
mongodb version => 1.1.2
libmongoc version => 1.3.1-dev
libbson version => 1.3.0
$ php -r 'echo MONGODB_VERSION, "\n";'
1.2.2
$ php -r 'echo phpversion("mongodb"), "\n";'
1.2.2
$ php -dmongodb.debug=stdout -r 'new MongoDB\Driver\Manager;' | grep Creating
[2016-03-01T17:59:23+00:00]     PHONGO: DEBUG   > Creating Manager, phongo-1.1.2[stable] - mongoc-1.3.1-dev(bundled), libbson-1.3.0(bundled), php-5.6.16
Sign up to request clarification or add additional context in comments.

Comments

8

Use pecl to check the current local version and the latest version available:

pecl search mongo

You should see this information:

Package Stable/(Latest) Local
mongo   1.x.x (stable)  1.x.x MongoDB database driver

Comments

6

For recent versions, the command is php --ri mongodb.

Comments

3

Run PHP test and check MongoDB section

<?php phpinfo(); ?>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.