Tracking a large amount of online users/guests

I am currently building a site which is going to have a lot of online users.

Ive been trying to think of some of the better practices i should use to do this. I have thought of the following:

  1. Use seperate online_users table - to store guests as well as registered users
  2. Set this table to be MEMORY to make it as quick as possible (doesn’t matter if the SQL server gets restarted as it is only online data)

I am not too sure though on the best way to populate/de-populate the database table. Obviously i can insert the user into the table, but how can i go about removing the inactive users from the table in an efficient manor?

Ideally I could probably just store the users id and then get the details from the main user table using that.

Thank you for your help.

You could store the sessions in a db table, depending on your app, if they’ve no session data stored but have a session, their a guest, if they have session data then their a member

Had forgot about the session data in the db. That should make life easier. Will make it super easy to track the guests. Cheers!

I had overlooked the possibility of the same user logging in multiple times. Thank you!

my approach to this was to have a table tracker which stores the user id (tracks registered members only), current page, page views, login time, last action, which auto-cleans once the session has become idle. The primary key is a tracker ID which I follow in the session from the moment they login.

It is interesting in a way just to know how many members are online, but to be honest I haven’t found a great deal of use for it.

What are the key details you want to know about your visitors that you need in realtime?

To remove inactive users you should probably setup a cron job to trim rows which have a last_activity < cutoff time.

if it possible that the same user is logged in more than once at a time (ie. multiple users per account), then you could use the session id as the unique identifier and keep the user id in a secondary field.