Is there such a thing as a listener in Ruby? I know they have session listeners for JSP, so I was wondering if there was something similar. Ultimately, I would like to create a listener to listen to when session are created or destroyed so I can display a count of how many users are currently online.
Share
You do not know how many users are online on a webserver, unless they have a permanent active connection (for example something like long-polling, comet).
Your best bet is to look into your session store and count the users that are active in the last X minutes.
A listener will not fire reliably when a user disconnects. For example with ‘login’ and ‘logout’ logic you will not get all logout actions, because internet connections can fail, users can forget to press the logout button, etcetera.
Update: for Rails, check this forum post: http://railsforum.com/viewtopic.php?id=18480 which explains the solution in more detail.