I'm working on an online system that allows users to interact socially and of course it will be important to be able to identify users that are in fact online. I know about HTTP being stateless and I know about using sessions, so I'll need to accomplish this by comparing the last active time of a user to an arbitrary expiration time.
My ultimate question comes down to this : Should I just add some fields to the existing members table (last_active_time
, is_user_online
, hide_online_status
, etc) OR would it be best to maintain this information in a separate table? My initial thought is to use the existing table for simplicity. Aside for level of complexity, what are the benefits/disadvantages of one vs the other?
I would maintain this within a separate table. If you have have a million users and you want to know who is online, you do not want to be scanning that table over and over again to find that information. Your "online" table will be relatively small and you can have a job that scans it periodically for those that have not come in in the past 5 min or so and then simply delete them from the online table and update anything necessary in the members table for "last_seen"