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

Troj's avatar
Level 4

Duplicate session query

On every page i've this duplicate session query, and i dont know where to start looking for the problem. Any suggestions?

select * from `sessions` where `id` = 'ZGtPxAAAlFsMcZOC4OXnwRRX8n8gf9uWsqeefjoP' limit 1
update `sessions` set `payload` = `sdffbbblablablverylong`
select * from `sessions` where `id` = 'ZGtPxAAAlFsMcZOC4OXnwRRX8n8gf9uWsqeefjoP' limit 1
0 likes
9 replies
bugsysha's avatar

Either use something like:

\Illuminate\Support\Facades\Event::listen(\Illuminate\Database\Events\QueryExecuted::class, function (\Illuminate\Database\Events\QueryExecuted $query) {
    var_dump($query);
});

Or install laravel-debugbar or maybe even telescope. You can see every query where it originated from.

Troj's avatar
Level 4

I found this because i have installed the debugbar. So i see the duplicate query, but i dont know where to start for the fix.

bugsysha's avatar

It says besides the query where it was executed from.

Troj's avatar
Level 4

You mean this: 163ms \vendor\laravel\framework\src\Illuminate\Session\DatabaseSessionHandler.php:91

bugsysha's avatar

You mean this: 163ms \vendor\laravel\framework\src\Illuminate\Session\DatabaseSessionHandler.php:91

Yeah, wasn't there a way to expand that and see where did it originate from?

Troj's avatar
Level 4

@michaloravec What does that mean? In my case it's always the first and the last query when i look at the debugbar.

And just before the last query there is an update sessions that sets a payload. Thats probably why the last one causes the duplicate one. So this might not be a problem? Is that right?

MichalOravec's avatar
Level 75

It means that in your app use database driver for session and you use it to store some informations. No, it's not a problem. Don't worry.

3 likes
bugsysha's avatar

Question is are you using session() anywhere in the code?

Please or to participate in this conversation.