[GH-ISSUE #962] Monolog MongoDBClient Error for php >7.0 #387

Closed
opened 2026-03-04 02:14:38 +03:00 by kerem · 5 comments
Owner

Originally created by @jeicken on GitHub (Mar 30, 2017).
Original GitHub issue: https://github.com/Seldaek/monolog/issues/962

Hello!

I am having an issue with using the Monolog MongoDB functionality with php 7.0.15.
The \Monolog\Handler\MongoDBHandler.php expects a MongoDB\Client which has been removed in php 7.0.15. This renders the Monolog MongoDB functionality unusable at the moment for php7, or am I missing something?

Best regards
Jan Eicken

Originally created by @jeicken on GitHub (Mar 30, 2017). Original GitHub issue: https://github.com/Seldaek/monolog/issues/962 Hello! I am having an issue with using the Monolog MongoDB functionality with php 7.0.15. The \Monolog\Handler\MongoDBHandler.php expects a MongoDB\Client which has been removed in php 7.0.15. This renders the Monolog MongoDB functionality unusable at the moment for php7, or am I missing something? Best regards Jan Eicken
kerem closed this issue 2026-03-04 02:14:38 +03:00
Author
Owner

@moderndeveloperllc commented on GitHub (Mar 30, 2017):

@jeicken This has more to do with which MongoDB extension you are using for PHP. MongoDB\Client is part of the new mongodb extension and is what the master branch is coded to. If you are using the old mongo extension, you really should look into upgrading if possible or stick to monolog 1.x versions as that code checks for classes from both extensions.

<!-- gh-comment-id:290462136 --> @moderndeveloperllc commented on GitHub (Mar 30, 2017): @jeicken This has more to do with which MongoDB extension you are using for PHP. `MongoDB\Client` is part of the [new `mongodb` extension](https://pecl.php.net/package/mongodb) and is what the `master` branch is coded to. If you are using the [old `mongo` extension](https://pecl.php.net/package/mongo), you really should look into upgrading if possible or stick to monolog 1.x versions as that code [checks for classes from both extensions](https://github.com/Seldaek/monolog/blob/1.22.1/src/Monolog/Handler/MongoDBHandler.php#L34).
Author
Owner

@jeicken commented on GitHub (Apr 3, 2017):

@moderndeveloperllc thank you for your answer.
I installed the newest PECL package on my server, the class MongoDB\Client can still not be found (I checked if the reference for the extension is correct in the php.ini).
It also states in the docs here, that there is neither a class MongoDB\Client nor \MongoClient available in the newest php mongodb extension.

I am using laravel 5.4 which is shipped with monolog 1.22.1 as far as I can see.

Any poking in the right direction is highly appreciated :)

<!-- gh-comment-id:291091012 --> @jeicken commented on GitHub (Apr 3, 2017): @moderndeveloperllc thank you for your answer. I installed the newest PECL package on my server, the class MongoDB\Client can still not be found (I checked if the reference for the extension is correct in the php.ini). It also states in the docs [here](http://php.net/mongodb), that there is neither a class MongoDB\Client nor \MongoClient available in the newest php mongodb extension. I am using laravel 5.4 which is shipped with monolog 1.22.1 as far as I can see. Any poking in the right direction is highly appreciated :)
Author
Owner

@stof commented on GitHub (Apr 3, 2017):

@jeicken the new mongodb integration for PHP is split in 2 parts:

  • the mongodb PECL extension for the low-level driver
  • the mongodb/mongodb composer package for the higher level API.

MongoDB\Client is part of the userland library, not of the C extension (they moved as many features as possible to the userland library as a PHP library is easier to maintain, to evolve and to receive contributions that a C extension, given that most PHP developers don't know C).
So you need to install that package to use the new MongoDBHandler, not only the C extension.

<!-- gh-comment-id:291092698 --> @stof commented on GitHub (Apr 3, 2017): @jeicken the new mongodb integration for PHP is split in 2 parts: - the `mongodb` PECL extension for the low-level driver - the `mongodb/mongodb` composer package for the higher level API. `MongoDB\Client` is part of the userland library, not of the C extension (they moved as many features as possible to the userland library as a PHP library is easier to maintain, to evolve and to receive contributions that a C extension, given that most PHP developers don't know C). So you need to install that package to use the new MongoDBHandler, not only the C extension.
Author
Owner

@jeicken commented on GitHub (Apr 3, 2017):

@stof Thanks pointing that out, tried with your supposed solution and all worked fine.

Would have been pretty nice to have that documented clearly somewhere. But maybe I am just too blind to see it ;)
Either way, this issue can be closed, thanks for the quick help guys!

<!-- gh-comment-id:291180122 --> @jeicken commented on GitHub (Apr 3, 2017): @stof Thanks pointing that out, tried with your supposed solution and all worked fine. Would have been pretty nice to have that documented clearly somewhere. But maybe I am just too blind to see it ;) Either way, this issue can be closed, thanks for the quick help guys!
Author
Owner

@stof commented on GitHub (Apr 3, 2017):

@jeicken the composer.json already suggests installing mongodb/mongodb to use the MongoDB handler.

<!-- gh-comment-id:291185274 --> @stof commented on GitHub (Apr 3, 2017): @jeicken the composer.json already suggests installing ``mongodb/mongodb`` to use the MongoDB handler.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/monolog#387
No description provided.