August 2016 ~ Coding Savvy
Coding Savvy FB Twitter Google

How to use Database ( MongoDb ) as session Handler PHP - 2016

By default PHP has an inbuilt session handler that stores session variable by saving session variables into a file. The native sessions just depend on writing a small cookie and file on the server. Database based session allows you to add security functionality to the session layer, Any performance lose or gain by putting your sessions in a database won't be noticeable for the vast majority of applications, however it's more secure if you put your sessions in the database, that being the most developers primary reason for doing so. Database-based sessions are also perfect in server farm environments because a user could visit each server in the course of their visit; file-based sessions would only be valid on that one server. But we can override PHP's built-in session handlers by using session_set_save_handler . When your app gets big and you start thinking of scaling Database based session makes things easier. MongoDB (from humongous) is a free and open-source cross-platform document-oriented database. You can read more about MongoDB at Using MongoDb is a way of separating the session management database from the primary sever Database, It is well known that most PHP websites use MySQL as their primary database. I prefer not to let the session handler implementation affect the primary database performance. MongoDb can also store some special data format and an Object as a whole without any data loss.
How to use Database ( MongoDb ) as session Handler PHP