Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

farzad's avatar

Laravel Session Driver, file or database?

Hi, i have a site and i use database driver for session but i don't now Which is better, File driver or database driver?

Thanks for your help

0 likes
10 replies
bart's avatar

As always: it depends. In My opinion the file driver should be the better choice. The disadvantage of using the database driver could be SQL server load whereas file access should be faster. Last but not least RAM is the fastest way of storing and accessing data.

3 likes
bashy's avatar
bashy
Best Answer
Level 65

Depends on your setup (a lot). Maybe you have multiple servers and a DB server, for that you'd want to use the DB to keep sessions across all servers.

I use the DB option just because my site isn't that big (500 unique a day). It also provides me with easy access to all the users logged in from a time period so I can track stuff.

8 likes
rspahni's avatar

In case you have a chance to work with Redis or Memcache[d], you may want to consider the cache driver, too. I'm using Redis for what it's worth.

2 likes
masterpowers's avatar

May You Show me How you did it in 4.2 maybe i can make it work in 5.1 Do You Have an DatabaseSessionHandler and SessionServiceProvider? Session table? Can You Share How you do it? Coz i might be missing something in my Code.

usamamashkoor's avatar

@bashy i am using Laravel 5.0 and i am also using multiple server of amazon dynamic auto i am facing the session issue on multiple servers of amazon. because each time the request is sent to a different server. So i get a TokenMismactch Exception laravel 5.0.

I am using a file base session driver.

What i want to know is that will changing my driver to database will also resolve the TokenMismatch Error because i am using CSRF protection..

Thanks and Regards M.Usama

1 like
mohitpawar10's avatar

@usamamashkoor You will need to use session driver as the database. You might be using file diver so once your user visits your website session will be stored in the file on that server. But If website load increases then load balancer will send the request to another server which will log the user out of the system. The different server can access database not single file.

1 like

Please or to participate in this conversation.