How to convert file to database in Magento?

Magento’s session goes the same way at the underlying as other programming framework. Main concept of session is to store Data and used whenever required. It is always kept in one of the four storage infrastructures, consisting of Database, Filesystem, Memcache and tmpfs-backed Filesystem, which can easily be chosen during installation phase and is not cared by developers as well as end-users. Generally, we just see it as a key-value map, almost enough for programming. However, what differentiates Magento from its counterparts is that it introduces grouping to manage session data for different usage. Magento keeps all session data in global variable $_SESSION, an array from programming view and then divides them into independent groups with each group represented by an array encapsulated by a session class. Magento itself is equipped with three session classes for customer, core and checkout. One of the key concepts of Magento is the session either customer session OR core session. Magento can be fully customized the way we require. Here is how to convert file to database in Magento. Basically Magento provides two type of session management. Session can be stored in Magento in two ways

1.File based session
2.Database based session

File based session

File based sessions are the sessions which are stored in files under var/session folder. Generally magento asks where you need to store session at the time of installation and we just simply select the file system from Drop down without knowing any thing.File based session are stable, simple and durable. It is simple because do not need any kind of setup. It is durable because you will not lose your data if the system restarts. It’s stable because most modern file systems use journaling to make sure that in the event of a system crash your session data is consistent

Database based session

Database based sessions are the session which get stored in the Database. The session data is stored in the Magento MySQL database with database session storage. The connection used here is same as the core connection. If you have more than one Magento frontend node in a cluster, in a filesystem based session storage scheme, they will need to share session data. One of the key benefits of using database sessions is the clustered environment support. Easy sharing of session data is another benefit of storing session in database. Database provides this capability quite easily. It also gives durability and stability. Normally, people do not choose this because they forget to select Database session form drop down list at the time of magento installation. One of the problems with database session storage is that it adds more load to the database. A site with lots of session and products gives extra load on database.

Magento stores session type information in app/etc/local.xml. session_save tag tells about the type of session.

To enable file based session make sure that you have a session_save tag like this


To enable database based session make sure that you have a session_save tag like this-


You can easily change file based session in to database based session or vice versa by just changing in session_save tag.