The situation is as follows. On Dev server, several projects are being developed simultaneously on both the 5th and 7th versions of PHP.

Live server is

  • PHP 5.5.23
  • mongo 1.6.6

extension_loaded ("mongodb") = false

extension_loaded ("mongo") = true

Dev server is

  • PHP 7.0.8
  • mongodb 1.1.8

extension_loaded ("mongodb") = true

extension_loaded ("mongo") = false

The site is written in Yii2, therefore, to climb and change something in the Framework is a bad idea.

Dev server starts to pour errors like these

Class 'MongoDate' not found

Class 'MongoClient' not found

As I understand it because of the backward compatibility of mongo and mongodb drivers. I tried to write my own wrappers classes and update versions of yiisoft / yii2 and yiisoft / yii2-mongodb. But this is also a very bad idea, as some "exotic" pieces of code have become incompatible with the new version.

Here is a piece of composer.json with packages.

"minimum-stability": "beta", "require": { "yiisoft/yii2": "2.0.4", "yiisoft/yii2-mongodb": "2.0.1", } "minimum-stability": "stable", "require": { "fxp/composer-asset-plugin": "v1.1.4", "yiisoft/yii2": "2.0.9", "yiisoft/yii2-mongodb": "2.1.0", } 

Is there a light at the end of the tunnel?

  • Rule dev / prod parity - during development and in production there should be the most identical environment. If you do not have the opportunity to roll back to the fifth version, I would recommend to develop projects of the latest version of PHP in the virtual desktop. - etki
  • These are too ideal conditions. I thought to transfer the development to LAN and torture already somehow. But then it becomes necessary to simultaneously deliver two versions of PHP 5 and 7 in parallel. As I understand it is achieved through cgi. But he never did that. If there is a manual for dummies with consecutive steps. Would be grateful - Ninazu
  • These are not ideal conditions, these are necessary conditions for your development. There are phpbrew for different versions - etki
  • phpbrew is suitable. Just digging in this application. Put the version of the 5th version into it. Now you need to configure the separation to be. For php-cli it helped. Version changes after phpbrew use php-5.5.23. How now same to turn with Apache? - Ninazu
  • To be honest, I did not use it tightly, but, most likely, it will be enough to specify the correct path in the settings (the one into which the corresponding file of the phpbrew module is copied) - etki

2 answers 2

If you use mongoDB for a project, you have only two options:

  1. write on php 5. * using the MongoClient class MongoClient roll back the prod to this version of php (there is no mongo extension on php7 yet)
  2. or rewrite everything to the mongodb extension completely and then there will be a launch option on php7. * and php5. * with the mongodb extension

Faced with the same problem, I simply rewrote the project on mongodb replacing mongo and its classes such as mongoClient unfortunately in php7. * There is no such extension (at least it wasn’t at the time of rewriting)

    No, the old MongoClient is incompatible with PHP7 due to internal API differences with PHP5