0

i need best way to find out how many people are online with long polling method.

why i need long polling method to acquire that?

i need to know how many person are online in my site.of course i can do this with some query and update it in my site by each page load but i think no way to use this method in chat room is there?

`lastvisit` >= DATE_SUB(now(), INTERVAL 5 MINUTE)

any solution for this?if i can acquire that with no server polling i do appreciate if you guide me to right direction

HiDd3N
  • 494
  • 6
  • 23
  • There are probably billions of people online at any given time, so good luck with that? – adeneo Dec 10 '12 at 00:23
  • @adeneo then how facebook findout if user is online or not?he use this method and he is good luck with that?i know he use his datacenter for this job but when apps growing i can grow servers.now what you offer for get how many people are online? – HiDd3N Dec 10 '12 at 00:48
  • One of the hardest parts of such a system is taking into account that the user could just be reading and not performing any actions, or the user could have left the site days ago and just did'nt close the browser tab. You should have a system where IP adresses are stored, as a session alone is not very accurate, and after a certain time the user is automatically logged out so as to avoid users who are'nt really online but who did'nt close the browser from being counted. There are some good suggestions in this [**SO question**](http://stackoverflow.com/questions/4073311/detect-online-users) – adeneo Dec 10 '12 at 00:56

1 Answers1

0

If you're using long polling, then the number of users will be the number of active connectons to the poll handler - i.e. the total number of connections less those for other URLs - which is trivial to extract from the output of mod_status, however you omitted to tell us what server you are using.

However, if it were me, I'd simply use a database bound session handler and count the current sessions from there (but it's equally possible to do this using file or memory bound session handlers).

Since changes in the numbers are likely to be small relative to the number of requests coming in, this could be collected based on a scheduled job or by comparing a random number against a threshold rather than collected on every request.

symcbean
  • 47,736
  • 6
  • 59
  • 94
  • then counting sessions is best way for me to get how many online user if they are chatting or do search or other functionality in my site – HiDd3N Dec 10 '12 at 00:50
  • i dont need the number but i want to know who is online and who is not – HiDd3N Dec 10 '12 at 00:52