# How to see who is online?

**URL:** <https://www.ruby-forum.com/t/how-to-see-who-is-online/93206>\
**Category:** Rails\
**Created:** [April 29, 2007, 8:17am UTC](https://www.ruby-forum.com/t/how-to-see-who-is-online/93206 "2007-04-29T08:17:27Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [April 29, 2007, 8:17am UTC](https://www.ruby-forum.com/t/how-to-see-who-is-online/93206/1 "2007-04-29T08:17:27Z")

</div>

dear all,

how can i see who is “online”, and show the total number of people on my  
web ?

thanks

-feng

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [April 29, 2007, 10:32am UTC](https://www.ruby-forum.com/t/how-to-see-who-is-online/93206/2 "2007-04-29T10:32:28Z")

</div>

On Apr 29, 2007, at 8:17 AM, Feng wrote:

> how can i see who is “online”, and show the total number of people  
> on my  
> web ?

Being online is an ill-defined concept.

An approximation that might be good enough is to maintain a field in  
the users table called last\_seen\_at. Update it at each request in a  
high-priority filter. Then define to be online using a time window,  
say 3 minutes:

class User  
def online?  
Time.now - last\_seen\_at \< 3.minutes  
end  
end

– fxn

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [April 29, 2007, 5:26pm UTC](https://www.ruby-forum.com/t/how-to-see-who-is-online/93206/3 "2007-04-29T17:26:29Z")

</div>

Thank you all 🙂

Now I know what to do. thanks again 🙂

-Feng

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [April 29, 2007, 3:11pm UTC](https://www.ruby-forum.com/t/how-to-see-who-is-online/93206/4 "2007-04-29T15:11:56Z")

</div>

You could also include an Ajax function in each page that hits a “I’m  
still here” URL on a timer, so you can tell if they’ve still got your  
page open even if they’re not requesting new pages. But, that  
demonstrates that Xavier’s assertion that “online is an ill-defined  
concept” is definitely true. Are they online if they opened your page  
12 hours ago and haven’t been near their computer since? So maybe the  
function only runs up to N times and then stops unless the page  
refreshes or changes . . .

But in the real world, if you want to know how many (most?) popular  
sites actually accomplish this - MySpace for example - they just use  
Userplane to do it for them. They’ve already figured it all out.
