Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Keep track of who is on website right now

How would I keep track of number of current sessions on my website?

like image 949
Rod Avatar asked Nov 05 '22 10:11

Rod


1 Answers

If you just want to know who's looking through pages on a little rinky-dink site, one way is to have an app-wide (or static) list of the latest requests, along with the date/time of the request. Whenever someone requests a page, remove all of the "old" hits (older than X minutes), and append (or update) the visitor's info with a date/time of now,

Note, for a really busy site, this would probably be a bad idea. A somewhat more scalable solution would be to have a 'last visit' column in your users table, and update that whenever the user requests a page. But that wouldn't be helpful to track anonymous/not-logged-in users.

Either way, to see who's "active", you go through the data and find all the visits/users with a last-visit time less than X minutes ago, where X is some number you feel is appropriate. 20-60 minutes is usually good enough.

like image 71
cHao Avatar answered Nov 15 '22 13:11

cHao