Is it possible to use MongoDB to store sessions in Symfony 2? If so, how?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I’ve done this with Mandango, but it should be easily convertable to use eg Doctrine’s MongoDB ODM or similar. I made a start, but it hasn’t been tested and I’m fairly sure it should be passed something different to a Mongo instance 😉 I’ve added placeholders or example code where appropriate eg:
which I’m fairly sure will need to change 🙂
Code is up on Github at https://github.com/richsage/Symfony2-MongoDB-session-storage – PRs welcome when you get it working!
Essentially, I’ve extended the NativeSessionStorage class, and adjusted the various methods to handle inserting, retrieving and updating session records in my Mongo database where appropriate. The class needs to be configured as a service, with the appropriate dependencies added in, and then this service is passed to the session configuration. Et voila 🙂