Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to track user online status?

I would like to capture the following parameters:

lastAccessedTime - The time when the user visited the site the last time (usually shown during the login process)

isOnline - A boolean to represent if a user is online or not.

a. Would it make sense to have these variables as part of the User table itself or should this be handled via a separate user audit table?

b. If certain SOAP / REST API's expose the functionality via API calls, how do you track the above parameters (e.g. Would you modify the lastAccessedTime in such cases - this might confuse the user if he logs into the portal, isOnline bit also will not make sense if the user does API calls).

like image 395
Joe Avatar asked Dec 15 '09 06:12

Joe


2 Answers

I would create a session table that links back to the user. Instead of an isOnline field, I would just run a query for sessions that have been active within the last x amount of time. I would also update that session field with each request, even if that request is coming through an API.

This does create some overhead in pruning the session table, but you also don't clutter up your user table with non-user information, which can't be pruned.

like image 176
Myles Avatar answered Sep 26 '22 23:09

Myles


Make the lastTimeActive a field in the user table, and update it with each page access. Your "Users Online" list is all users whose lastTimeActive is within 5 minutes.

like image 34
Sampson Avatar answered Sep 26 '22 23:09

Sampson