I want to add online/offline
system to my project, but I'm confused with the best method to do it.
On login and log out, it's easy to update the column online
on the database with false
or true
User Table:
---------------------------
| ID | Email | online |
---------------------------
| 1 | test@g.co | 0 |
---------------------------
| 2 | te@g.be | 1 |
---------------------------
But the problem is when the user closes the browser without sign out, how I can update the online column with false
?
So, I thought by using an ajax running every 4 or 5 min, to call a function checking if users stay online or no.
But I think that this method is not professional, and it can be heavy on the website (to run a script) can make the website slow.
Is there any best method to do this ?