Display rolling hit counter

I’m trying to work out the logic behind a constantly updating (animated?) hit counter. It will display clicks tracked from other sites, so I expect the number to be quite large, and jump quickly. However, I’d like it increment by 1 just so the user has a visual grasp of “real-time” stats.

addroid’s website has a great example of what I’m trying to accomplish.

Is it all just smoke and mirrors ? I’m aiming for if two users side by side see the site, the number is the same. If the user refreshes the page, the number displayed isn’t lower than what they just saw (assuming the ticker faked incrementing and there were no actual hits). Not really wanting to “fake” the numbers at all.

Cheers!

Most ‘counters’ in that sense are smoke and mirrors - they estimate hits per second and get a start value, and just keep ticking along.

The trick with doing this is that you’re potentially generating thousands and thousands of additional requests going through your server every minute if you try and do this (60 * number of users) in real time.
This is also almost entirely a Javascript question, as the counter would have to be polling AJAX consistantly. The only PHP you’d need is <?php echo $numberofhits ?> (Well, a bit more than that, but you get the point) in your AJAX-receiver.

The first step - since you want to imitate what you have seen - is to determine how they do it.
Viewing the source of that page (on addroid.com) you will see this Javascript code.

It appears to be powered by a small PHP script that, probably, grabs the actual data.

I think AJAX will be a solution in your case.

Just have one piece of code to update visits number, then add another ajax script to read every 5 seconds that entry and display it.