Live data from Hacker News

Show a real-time user count without any client-side Javascript

minipenguin.com

21–24 of 24 posts

Re: Show a real-time user count without any client-side Javascript

#21
post #18

very cool, and apparently quite simple. but when I look at the network log with the developper tools apparently chrome doesnt register loading a new image. is it possible that it will never show up there because it doesnt finish loading? looking at the response headers of online.png shows: Cache-Control:no-store, no-cache, must-revalidate, max-age=0, post-check=0, pre-check=0, false Connection:Close Date:Sun, 29 Jul…

Ah, but then click "View Source" next to Response Headers and you'll see the non-evaluated headers: http://i.imgur.com/Ql741.png

  HTTP/1.1 200 OK
  Connection: Close
  Expires: -1
  Last-Modified: Sun, 29 Jul 2012 17:44:35 GMT
  Cache-Control: no-store, no-cache, must-revalidate, max-age=0, post-check=0, pre-check=0, false
  Pragma: no-cache
  Content-Type: multipart/x-mixed-replace; boundary=--whyhellothere
  Date: Sun, 29 Jul 2012 17:44:35 GMT
  Transfer-Encoding: chunked
Also, it can be any image type (or file type, for that matter) besides image/jpeg. In my program, I'm sending image/png so that the rendered font is more readable.

Re: Show a real-time user count without any client-side Javascript

#22

Why does his implementation say 130 users online and his sidebar widget says 29?

Darn. Yep, I can't figure out how to fix the bug causing that. I went to sleep hoping that it would in fact not be bugged and return to near-zero by the time I woke up, and now I can see that the bug is still very much there. Hmm.

Re: Show a real-time user count without any client-side Javascript

#23

Earlier quoted context omitted.

Yep, I like this as well. I'm an 18 year old cofounder/designer hacker and sent him an email to hopefully get connected. I'm always on the lookout for young people like me that have started early. (not to bash on anyone that started late, but it's cool to meet people along my same path)

Wish there had been more hackers around when I started at the age of 15. But then that was 1972 :-)

Well I wish I was alive in the 1970's. Seems like hacker heaven back then... albeit with no easy way of learning.

Re: Show a real-time user count without any client-side Javascript

#24
This is similar to the COMET/AJAX push model: http://en.wikipedia.org/wiki/Comet_(programming)

As HTTP is stateless it's hard to tell when a user has disconnected, you can make the count more accurate by starting a session for each user then incrementing a "last_connected" timestamp by N seconds for each hit (can you tie this to each COMET update? Perhaps with JS?), then expiring any sessions that haven't been updated for a while. This is how a few popular CMS' (Drupal, Joomla) implement the "Who's Online" count.

Post reply on HN