I want to count online users in my website.
The way which I found in most of the websites is that to insert a new row in a table containing user's IP and visit time and consider an idle time for example 3 minutes and in each visit delete table rows which are for more than 3 minutes ago and to show online users by counting table rows .
The problem is that this approach is not precise, for example an online user could be idle for more than 3 minutes but in this way only users which their last activity on the website is less than 3 minutes are counted. the other problem is that it is possible a user visit site and exit after 1 minute and by this way this users is still counted as online for 3 minutes.
Do you know a more precise way for counting online users?

Member Avatar

I don't know how this can be made more precise without looking at some expensive timed ajax action. An idle client would need to send data to the server just to say "I'm still here!" However, what if an user have 20 tabs open with your site on it - and there were 100 of them. Ouch! OK, perhaps not likely, but timed ajax calls hurt. Anybody else?