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

Alexsi's avatar

spatie/laravel-activitylog Session Lifetime register in the database

Can anyone suggest how the expired session can be recorded in the database?

Thanks to anyone who can help me :-).

0 likes
6 replies
Snapey's avatar

Nothing is monitoring session expiry, so you cannot log it.

There is a cleanup job that randomly deletes expired sessions but I doubt you could hook into that.

Consider the case where you have just one user on your site. They connect and a session is created, they continue to use the site and the session is refreshed. At some point they just go away (close their browser, shut down the device etc) That session is just sat there. It is not being looked at and no scripts are running on your server. The session data has an expiry time on it.

Some time later, the user returns and a new session is started. Now there are two session files, one is expired and one is new. The expired one sits there until selected randomly for deletion.

1 like
Alexsi's avatar

Snapey thanks for the reply. Currently I register login and logout (if it is done), but if the user expires the session I can not understand the time of activity. I would need to understand how long a user has been active for that activity. Can not do anything?

Snapey's avatar

Only if you record the users 'last access'

Use a middleware to update a database record or redis entry each time the user sends a request.

1 like
Alexsi's avatar

Snapey I use spatie/laravel-activitylog to record all activities in the database the only activity I can not record and the session expired :-( .

Snapey's avatar

Yep

(use @ when you mention someone so that they see the bell)

Please or to participate in this conversation.