2

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...

  • Possible duplicate of https://stackoverflow.com/questions/34486808/installing-the-php-7-mongodb-client-driver/34584135 I realized. – Will Jan 04 '16 at 03:00

2 Answers2

2

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

manuelbcd
  • 3,106
  • 1
  • 26
  • 39
0

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.

Will
  • 24,082
  • 14
  • 97
  • 108
  • First of all, thx for edit. From right question to wrong. I know about last commit. I know about new driver. I'm finding the way to use legacy driver with PHP7. That's what I'm asking about. – Eugene Gorbov Jan 04 '16 at 02:02
  • No problem. Right, the legacy driver simply won't work with PHP7. You'd have to modify it by hand to be compatible with the new API. I think this would be a good time to switch to the new driver. – Will Jan 04 '16 at 02:56