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

vincent15000's avatar

Is it possible to bind the expiration of a session to an event ?

Hello,

I'm searching how to bind the expiration of a session with an event.

'lifetime' => 120,
'expire_on_close' => true,

In the users table, I have a connected field to identify who is connected.

When the lifetime is over or the browser is closed, I want to automatically set connected to false.

How is it possible to do that ?

I had the idea to make an event (session expired event) and with a listener I could update the connected field.

I have searched without finding any solution.

Thanks for your help.

Vincent

0 likes
5 replies
tykus's avatar

PHP sessions do not work like that; nothing happens with the session unless there is a Request that check the Session.

You can use a Presence channel to achieve the type of functionality you need.

1 like
vincent15000's avatar

@tykus Thank you ... well ... I just read the documentation and I don't really understand the difference between standard channels and presence channels. Could you explain me this difference please ?

tykus's avatar
tykus
Best Answer
Level 104

@vincent15000 I assume you want to know who is connected???

Presence channels build on the security of private channels while exposing the additional feature of awareness of who is subscribed to the channel

1 like
vincent15000's avatar

@tykus Ok ... so the connected field is perhaps not so important, I just have to subscribe to a presence channel to know the number of connected people ... I didn't understand it like that ... thank you for the explanation ;).

tykus's avatar

@vincent15000 correct about the connected field on the Model.

If you're all set, please mark the thread closed.

1 like

Please or to participate in this conversation.