Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check MongoDB php driver version

Tags:

php

unix

mongodb

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?

like image 963
dykw Avatar asked Sep 26 '13 16:09

dykw


4 Answers

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
like image 94
bjori Avatar answered Oct 22 '22 07:10

bjori


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
like image 22
anhlc Avatar answered Oct 22 '22 08:10

anhlc


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

like image 37
olvlvl Avatar answered Oct 22 '22 06:10

olvlvl


Run PHP test and check MongoDB section

<?php phpinfo(); ?>
like image 3
Satish Avatar answered Oct 22 '22 08:10

Satish