views:

357

answers:

2

What is the simplest way how to check if user is online and display list of online users?

The only way I can think of is some periodic polling server to update last action timestamp, and when last timestamp is more than xx ago, user is considered to be offline. But it doesn't seem like too eficient solution.

+1  A: 

You could potentially check the session time, if you use database session store. When the updated_at extends past a certain time, assume the user is no longer active. This could be problematic as well, however.

Being honest, it's a somewhat difficult scenario to tell the active number of users without some form of periodic server polling. Your thought is not a bad one.

Eric
+5  A: 

Authlogic can do this by default, and is a great authentication system that is very powerful. I would suggest migrating your current authentication system over to it (maybe a days worth of work, depending how customized your system is).

If you can't (or simply don't want to) move your application over to Authlogic, you can check out the source code at the link above, as well as an example project here.

Mike Trpcic
Thanks for pointing him to that. I myself have never heard of Authlogic, but am interested in it now, so you have provided us all with some decent information :)
Eric