Eugene Gorbov
Eugene Gorbov

Reputation: 45

Using "Legacy" MongoDB Driver with PHP7

Is there a way to use the Legacy Mongo PHP Driver from PECL with PHP7? Maybe unofficial fork with PHP7 support or compile/modification instruction...

Upvotes: 2

Views: 2383

Answers (2)

manuelbcd
manuelbcd

Reputation: 4577

There is an alternative if you really need to use any bundle or library with strong dependencies on php mongo legacy driver, it's called "alcaeus:mongo-php-adapter". It provides an ext-mongo library on top of mongo-php-library (sic).

https://github.com/alcaeus/mongo-php-adapter

If you face any problem with composer related with the absence of legacy driver (Famous message "The requested PHP extension ext-mongo * is missing") you can fix it adding that to composer.json

"provide": { "ext-mongo": "1.6.12" },

In this case may be you want to take a look to this thread (same situation but with heroku): https://github.com/alcaeus/mongo-php-adapter/issues/67

Upvotes: 2

Will
Will

Reputation: 24709

No, the legacy driver does not support PHP7. Here's the commit and the JIRA Ticket where this was officially finalized.

The new PHP MongoDB driver can be found in PECL here (or GitHub).

To install, just:

pecl channel-update pecl.php.net

pecl install mongodb

echo "extension=mongodb.so" >> `php --ini | grep "Loaded Configuration" | sed -e "s|.*:\s*||"`

The documentation for the new driver can be found here. I'd like to include a note from the documentation:

Ultimately, this extension is not intended to be used alone. Users should considering using this driver alongside one or more userland PHP libraries, such as mongo-php-library.

The new mongodb driver / PHP extension is a lot more low-level than the legacy mongo driver, and you are encouraged to use a higher-level library on top of the driver rather than using it directly in your code.

The Mongo PHP Library (releases) is the official high-level library for PHP, and it's what is recommended to use in your projects. It's still in Beta, but this still seems to be the safest and most-future-proof path forward with PHP7.

Edit: The Legacy Mongo Driver is no longer active at all.

Upvotes: 0

Related Questions