2

I am always curious how different sites function.

I am assuming the site in general can be built purely in PHP and javascript and that the timer is basically running on an ajax call but how does the internal server/client machine keep everybody's computers in sync at the same time (especially given JS is a client-side language)?

If it is in fact making ajax calls (apparently every 1/5 of a second) in order to keep up with the bidding/timer settings, what type of hardware and bandwidth does a site like that have to maintain?

Are there better languages for sites like these in reality?

Thanks ahead of time!

Update

I am not asking how to create a display of a countdown in JS ultimately - how does the relay back and forth take place between the two (server and end user)

JM4
  • 6,356
  • 18
  • 74
  • 121

1 Answers1

1

They use the server's time and then output it to the client.

wherein the javascript then decrements it the same on each client.

This is no hit on the server. the decrement is on the client side, not on the server, as in it is not an ajax call.

for example:

var serverTime = getServerTime();

setTimeout(function(){serverTime--;},1000); 
//decrement by one every 1000 milliseconds (1 second)

And on each of those sites there could be a Comet (or any other long polling) in the background that when there is a change, the getServerTime() is called again.

This is not much of a hit on the server, like for example with Comet programming it is a hidden iframe that would call js scripts when they are needed.

see here:

Comet and jQuery

Community
  • 1
  • 1
Naftali aka Neal
  • 138,754
  • 36
  • 231
  • 295
  • maniator - that was my assumption but even still, the relay between server time and having the ajax call over and over and over (there are no push notifications on a site) must be incredible, no? – JM4 Mar 15 '11 at 04:33
  • see my amendment to the answer – Naftali aka Neal Mar 15 '11 at 04:34
  • maniator - there has to be a server relay when a bid is placed in which each bidder's counter is reset to a predetermined value – JM4 Mar 15 '11 at 04:36
  • that would be set somewhere in the `getServerTime()` function in the example above. – Naftali aka Neal Mar 15 '11 at 04:38