NYCPHP Meetup

NYPHP.org

[nycphp-talk] Hmm, how to count 'online' users?

Steve Manes smanes at magpie.com
Thu Aug 12 13:08:20 EDT 2004


ophir prusak wrote:

> Then, every 5 minutes delete from table where last seen > 10 minute ago.
> Instead of updating the last seen column EVERY time a logged in user 
> views a page, store a cookie that says when they last told the server 
> they were seen.
> If it's over 5 minutes, then update the database. That way you're 
> guaranteed at most one update per online user per 5 minutes.

Good solution.

Another, somewhat wackier one is to embed a 1x1 on each page, its 
argument being the user's authenticated login name.  This would make a 
request to a dedicated server running either a script or possibly an 
Apache module that would extract the username and update a heap table 
with the current time.  Every couple of minutes the table of usernames 
would be dumped to an HTML file for display in your "Who's On" list. 
Every 30 minutes or so, a script would purge names with last-request 
times > 30 minutes.

This presumes a dynamic web site.  What's nice about this approach is 
that it's decoupled from your main web site and database, which doesn't 
have to do anything to maintain that list.






More information about the talk mailing list