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

LunaLlena's avatar

Trigger code execution when session expires

Is it possible to trigger the execution of code when a session expires?

0 likes
10 replies
haakym's avatar

What is it you're trying to do exactly? Please provide more details.

LunaLlena's avatar

Other platforms have a way to execute code when a session ends. For example, ASP.net has a 'Global.asax' file with a function call 'Session_End()' where you can add code that it is executed every time a session ends. Is there anything similar in Laravel?

ohffs's avatar

By 'session' do you mean a user logs out (or times out) - or the end of the current code run from a request?

LunaLlena's avatar

I mean that session times out. If a user logs out I can execute code when he/she logs out. That would be part of the request cycle. What I am asking is about the possibility of execution of code when a session times out, when there is no user intervention.

LunaLlena's avatar

Thanks 'ohffs', I am going to have a look at it. I'll give feedback.

sitesense's avatar

Alternatively, just before the session ends you could popup a "Session will expire in 'n' seconds" reminder and if no action is taken - do your stuff.

Please or to participate in this conversation.