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

PaulDiamant's avatar

Laravel authentication session/database, 1 session per IP/user_id

Hello, in my sessions.php config file, I set the auto expire on close to true and the session type to 'database' so it's stored in the database everytime a user goes on the site and logs in. Now, it works fine but the sessions just keep stacking up with the same user_id and IP address, I want to have a list of active sessions within the last 10 minutes only, NO USER ID or IP address duplicates because they don't get deleted... how would I go about doing it?

This is how it's looking in the database: http://image.prntscr.com/image/8ce1d42943d948b18a23904253c7792f.png

0 likes
1 reply
willvincent's avatar

You could run a scheduled task every 10min that deletes entries from the session table where the last_activity is < the current unix timestamp..

or maybe increase the odds of the garbage collection lottery hitting, so expired sessions are cleared out more often.

Please or to participate in this conversation.