Reputation: 585
I wonder if this is a good solution for a medium size social site. Its about managing online/offline indications of users. My solution is to include a script on each page that first of all updates the "last activity" field of the current user with a timestamp, then i select all users that havent been active within the session expire time(but is still online accordingly to the table) and sets the online flag(in db) to false. Is this a solution that is commonly used or will the sever load be to much when a bigger amount of users are navigating throug the site? Is there any better solution? Be aware that im not only intrested in the amount of online users but also names, therefore a session based script seems to complicated and inaccurate.
Thanks in advance!
Upvotes: 1
Views: 337
Reputation: 128
A table that stored sessions should contain a field called "LAST_ACTIVITY_DATE", TIMESTAMP. So whenever they load a new page or you update something with AJAX, just update LAST_ACTIVITY_DATE with current_timestamp.
Then when you need to get online users, get those who have last_activity_date within 5 minutes from Current_timestamp.
Easy as!
Upvotes: 1
Reputation: 254916
It is good enough but better you could store this information in activity
table: for any active user insert/update a row with his user_id
and for inactive for more than N minutes one - remove rows.
Upvotes: 1