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

Thomas_Emad's avatar

Files or Database driver Sessions in Laravel ?!

as a default thing in Laravel 11.x, Session Driver is Database.

But I want to think a little bit deeper, how much if it is taken as automatic, although it puts some effect on the duration of the queries (try in Laravel Telescope), which will find that the files are less than the Database by about 100ms (files session driver is winer here), I know it is relatively small but if there are many users at the same time on the database, I think it will have a negative effect?

The same question but in the opposite direction, what will happen if the driver files and there are many users?

0 likes
10 replies
jlrdw's avatar

Generally you can just use file for session, but something like a load balancer you need database.

File used to be the default, I have no idea why now it's database.

But just because it's default doesn't mean you have to do it that way.

2 likes
Thomas_Emad's avatar

@jlrdw yes sure, but i just think why it now the default, also it make different effect in queries durations

Snapey's avatar

Only measure the speed difference on prod. Locally your timings could be different.

File is ok when you only have one webserver. After that you are going to need a shared session store.

1 like
JussiMannisto's avatar

DB sessions are a bit easier to develop on because you can inspect the session table at any time. I prefer DB in general because it gives you better control over sessions.

100ms seems like a lot. I just did a couple of tests on my desktop with sqlite and mariadb. Session reads were measured in microseconds, writes took ~1-2ms. There was no measurable difference in page load times vs. the file driver.

3 likes
Thomas_Emad's avatar

@JussiMannisto I think it depends on the power of the device to perform the query time, also you should test in really project not emtpy

JussiMannisto's avatar
Level 50

@Thomas_Emad I don't know what kind of "technical way" you're after.

Session reads and writes use a primary key. That means the time complexity of a query is at worst O(log n). I could populate the session table with millions of rows, but I know it wouldn't affect query times in any real way because of how databases work.

Session data is read once per request and changes are flushed to the DB once, at the end of the request. So you'll have one lookup and one write per request. The delay of these queries is insignificant compared to the boot time of the app. And yes, even if you use Octane.

We've used database sessions on live apps for years without issues. If you have a very high traffic site, other parts of your app will start breaking before your sessions do. But if you need better session performance, you can always switch to Redis.

3 likes
Snapey's avatar

@Thomas_Emad why so insulting? We are giving up our time to try and help.

What answer were you expecting?

1 like
Thomas_Emad's avatar

@Snapey I am very sorry, I did not mean any insult in my words, I only meant if it had any technical aspect, sorry again for not clarifying my intention

Please or to participate in this conversation.