# PHP "online now" feature

**URL:** <https://forum.kirupa.com/t/php-online-now-feature/183066>\
**Category:** programming\
**Created:** [March 23, 2006, 4:01pm UTC](https://forum.kirupa.com/t/php-online-now-feature/183066 "2006-03-23T16:01:33Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mickshake](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/mickshake/32/1353_2.png) [@mickshake](https://forum.kirupa.com/u/mickshake)\
**Post date:** [March 23, 2006, 4:01pm UTC](https://forum.kirupa.com/t/php-online-now-feature/183066/1 "2006-03-23T16:01:33Z")

</div>

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.

Thanks!  
-mickshake

---

<div class="post-metadata">

**Author:** ![JoshuaJonah](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/joshuajonah/32/1775_2.png) [@JoshuaJonah](https://forum.kirupa.com/u/JoshuaJonah)\
**Post date:** [March 23, 2006, 4:15pm UTC](https://forum.kirupa.com/t/php-online-now-feature/183066/2 "2006-03-23T16:15:16Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![mickshake](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/mickshake/32/1353_2.png) [@mickshake](https://forum.kirupa.com/u/mickshake)\
**Post date:** [March 23, 2006, 4:20pm UTC](https://forum.kirupa.com/t/php-online-now-feature/183066/3 "2006-03-23T16:20:40Z")

</div>

A flag, or a timestamp?

And what happens if they never click “logout”?

---

<div class="post-metadata">

**Author:** ![JoshuaJonah](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/joshuajonah/32/1775_2.png) [@JoshuaJonah](https://forum.kirupa.com/u/JoshuaJonah)\
**Post date:** [March 23, 2006, 4:22pm UTC](https://forum.kirupa.com/t/php-online-now-feature/183066/4 "2006-03-23T16:22:46Z")

</div>

they timeout after a period of time
