Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best way to keep track of current online users

I have a requirement that my site always display the number of users currently online. For example, "35741 Users Currently Online". This is not based on a log in, simply how many users are currently on my site. I have tried using Session Start/Session End for this, however session end is not reliable. Therefore I get inflated numbers, as my session start adds numbers but session end doesn't remove them because it doesn't fire.

There is no additional information to be gathered from this (reporting, etc), it's simply requested that the number show up. Very simple request that's turning into a huge deal. Any help is appreciated.

EDIT:

I should specify that I have also tried using a database for this. Simple table that contains a session ID and a last activity column. With each page hit, I check to see if the session is in my database. If not, insert. If so, update with activity time. Then I run a procedure that sweeps the database looking for sessions with no activity in the last 20 minutes. This approach seemed to kill my SQL server and/or IIS. Had to restart the site.

like image 982
mlb Avatar asked Nov 30 '09 22:11

mlb


People also ask

How can I see the active users of a website?

See Active Users dataSign in to Google Analytics. Navigate to your view. Open Reports. Select Audience > Active Users.


4 Answers

Best way is like you do, but time it out via activity. If a given session doesn't access a page within 5 minutes or so, you may consider them no longer active.

like image 166
Noon Silk Avatar answered Nov 07 '22 12:11

Noon Silk


If you're using ASP.Net membership, take a look at GetNumberOfUsersOnline.

like image 45
Scott Ivey Avatar answered Nov 07 '22 14:11

Scott Ivey


For every user action that you can record, you need to consider them "online" for a certain window of time. Depending on the site, you may set that to 5 minutes. The actual web request should take less than a second. You have to make some assumption about how long they might stay on that page and do nothing but be considered online.

This approach requires that you keep track of the time of each users last activity.

like image 34
Larsenal Avatar answered Nov 07 '22 14:11

Larsenal


Use Performance Counters:

  • State Server Sessions Active: The number of active user sessions.
like image 2
Remus Rusanu Avatar answered Nov 07 '22 13:11

Remus Rusanu