PHP "online now" feature

Lots of sites (including kirupa) have the ability to show who is “online now”.

I’m curious which method is faster, or if there is one I’ve yet to think of:

  1. New table in a mySQL DB named… say “onlineNow” which would keep records of users logged in by: inserting a new row on login and then updating that row periodically when they navigate throughout the site with a time stamp. After 10 minutes of no activity it would clear this row

  2. New row in an existing “users” table to hold a timestamp of their last action and if it’s been 10 minutes or more since, set it to ‘offline’

  3. Scan the servers Sessions for their username

Both of these would be pretty heavy on the server when traffic is high, my guess is option 2 would be a little less work for the server.

Any comments or suggestions would be great!

PS. Mr Kirupa, if you just want to share with me how you’ve pulled it off on this site, thats basically what I’m looking to achieve.


I would think a flag in their user record is set, then unflagged on logout

A flag, or a timestamp?

And what happens if they never click “logout”?

they timeout after a period of time