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

keyur's avatar

Session queries are taking a long time

Hello,

I noticed through NewRelic that laravel seems to be performing session cleanup queries on my pages. It's hard to tell if it is happening on every page or certain pages.

But when it does, it seems to be very slow. My sessions are configured to last for 100 days and are stored in the database. Here's a snip from NewRelic showing the query time.

Image of Query

Any idea how to make this faster?

Thanks.

0 likes
2 replies
JacDev's avatar
JacDev
Best Answer
Level 1

I don't know where this session tables comes from, but as a DB expert, I would suggest just putting an index on the 'last_activity' field. That would speed up the searches in the tables (if it isn't already indexed).

keyur's avatar

thanks, that did solve the issue!

Please or to participate in this conversation.