Forum Moderators: phranque

Message Too Old, No Replies

Will this be stress on the Server ?

         

smagdy

10:56 am on Apr 18, 2008 (gmt 0)

10+ Year Member



Hello!

I have been trying different approaches to make about 20 different countdowns on PHP page..

so first using the clients clock wouldnt make the information in sync with the server, so i had to get the time from the server by Ajax.

So my question is, will it be stress on the server to query the time using ajax like 20 times per second for the 20 different counters?

In other words, every counter (20 counters) will get the current server time and make the calculations and display.

I get the date by PHP like this <?= strftime('%c') ?>

The code works perfectly and the counters looks great n different computers (syncing correctly) but I just want to know if i need to try something different if this will cause stress on the server..

Thanks in advance

jdMorgan

2:24 pm on Apr 18, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Get the time once per second, then base all counters on that locally-saved value.

Or get the time only a few times per user session, calculate the offset from the user's local clock, and base all of your calculations on that adjustment value. In this way, you could request the server time only once every five minutes or so.

Be aware that your original method may fail badly for users on dial-up or satellite connections, where the request latency might easily exceed the time between requests. For example, the minimum latency for a satellite request is 480 milliseconds, or almost ten times slower that the period of your 20 requests per second.

Twenty requests per second would require a "perfect-quality" high-speed connection (i.e. no TCP/IP packet delays or losses), and would put quite a load on your server if you have many users.

Jim

smagdy

2:47 pm on Apr 18, 2008 (gmt 0)

10+ Year Member



Thanks, I tried this another way which i get the serverTime just once then i get the Client time and calculate the difference..

for ex. if its 30seconds

then i use the Client time normally and always add those 30 seconds.. it looked fine on Mac but the time was different on mobile phone browser.. so i am afraid that javascript wont calculate this write in any computer..

Here is what I did...

st = new Date(serverTime); //serverTime was saved once by ajax call

ct = new Date();//Client Date

ct_st_diff = new Date(ct - st);

ct_st_diff = Math.floor(ct_st_diff.valueOf()/1000); //Get difference in seconds

var seconds = ct.getSeconds()

if(ct > st)
seconds += ct_st_diff;
else
seconds -= ct_st_diff;

ct.setSeconds(seconds); //Add the extra seconds

is there a better proper way to calculate the difference between Server and Client then add it to Client Time... ?

Thanks again