Im trying to create some kind of forum, and I want to know how many users are online in each of the topics (not in the main website). I can create a table in te database that counts the users that enters each Topic actionView($id), but the problem is that if suddently one closes the chrome… I do not know how to decrease the online users of that topic.
Is there any way to do it with sessions (in my website the ussers have to sing in and sign out).
It will be very easy if there is a method that triggers once a users close the browser suddenlty without clicking sign out action.
If precision for number of online is very important then you might need to have setInterval of javascript and send ajax to update it.
Or you can rely on last_seen (datetime when user saw that form) in this way you can simply consider user is viewing topic if this is in between 0 to lets say 5 mins?
You can’t really rely on window close event as it might not sent request before you can actually close window. If there is a delay, users will wonder why close didn’t work