Answer the question
In order to leave comments, you need to log in
Symfony2.8 Sessions in MongoDB. How to set up correctly?
Hello.
For a project on Symfony (v2.8.9) I'm trying to set up session storage in MongoDB. The server has PHP7.0.8 installed. The mongodb driver is installed via pecl and extension=mongodb.so is added to php.ini sudo pecl install mongodb
I configure Symfony as described in the " How to Use MongoDbSessionHandler to Store Sessions... " document, substituting my data for connecting to the database
# app/config/config.yml
framework:
session:
# ...
handler_id: session.handler.mongo
cookie_lifetime: 2592000 # optional, it is set to 30 days here
gc_maxlifetime: 2592000 # optional, it is set to 30 days here
services:
# ...
mongo_client:
class: MongoClient
# if using a username and password
arguments: ['mongodb://%mongodb_username%:%mongodb_password%@%mongodb_host%:27017']
session.handler.mongo:
class: Symfony\Component\HttpFoundation\Session\Storage\Handler\MongoDbSessionHandler
arguments: ['@mongo_client', '%mongo.session.options%']
# app/config/parameters.yml
parameters:
# ...
mongo.session.options:
database: session_db # your MongoDB database name
collection: session # your MongoDB collection name
mongodb_host: 1.2.3.4 # your MongoDB server's IP
mongodb_username: my_username
mongodb_password: my_password
ClassNotFoundException in appDevDebugProjectContainer.php line 2232:
Attempted to load class "MongoClient" from the global namespace.
Did you forget a "use" statement?
ClassNotFoundException in appDevDebugProjectContainer.php line 2232:
Attempted to load class "Manager" from namespace "MongoDB\Driver".
Did you forget a "use" statement for another namespace?
Answer the question
In order to leave comments, you need to log in
Probably, the information in the dock refers to the old driver. Add dependencies:
The Mongo PHP Adapter is a userland library designed to act as an adapter between applications relying on ext-mongo and the new driver (ext-mongodb).
It provides the API of ext-mongo built on top of mongo-php-library, thus being compatible with PHP 7.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question