Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Who's Online in Pylons

I currently have a Pylons application running with a basic user system set-up. I want to try and create a widget that shows the users that are currently logged on to the website. I'm not sure how I should handle this though; I'm not sure if pylons sessions being active are based on whether or not a user is actually on the web apps page or not, so I am seeking some ideas as to how I can work with what I already have possibly to accomplish this.

like image 544
user183430 Avatar asked Nov 20 '09 02:11

user183430


1 Answers

There's several ways you can do it, depending on how accurate you want to be.

The easiest, and first way to do it, use memecached or a persistent store to keep track of users, and the last time they hit a page. Consider anyone that has hit a page within X minutes to be 'logged in', as long as they're not 'logged out'. If you just update the db every page hit, or update memcached (or faster db), then query it for sessions within the last minute.

Second, but more intensive on your server, put Javascript on every page, that hits a special URL on your site every XX seconds/minutes to indicate the user is logged in. Record that, and use that count. This has the advantage that your JS could keep the counter on the page up to date in real-time. Though the polling might be expensive on your server.

Or third, use a Comet style system, say with Orbited, and as long as the user is on a page connected to the server, the connection will be open, and you can track how many open sessions you have. Orbited can handle around 10k open connections at a time per server I believe.

I'd recommend the first type as it requires the least extra overhead/setup and handles the fairly common case. If you're using real-time chat where you need more accuracy consider one of the other two.

like image 59
Ben Bangert Avatar answered Nov 13 '22 16:11

Ben Bangert