Jump to content

Multi user auction timer not updating correctly all the time


MrMastermind

Recommended Posts

Hi,

 

We're currently testing an auction timer which updates the auction clock every second and als updates the price accordingly, using Ajax Prototype periodicalupdater() and javascript setInterval().

 

During testing we noticed that sometimes the clock skips a few seconds. Now I can imagine that this is due to the load the server gets from every update it has to do for every visitor that attends the auction. I can also imagine that this gets worse when more visitors attend the auction.

 

So the question is, am I correct about the load? And is there a way to make sure the updates occur correctly for every visitor, giving them an equal change at the auction? Would it be possible to use a server-side push? or do we need to switch to another language other than PHP for that?

 

 

Here's most of the code used for the clock:

 

if (window.ActiveXObject){

var http;
var timerID = 1;

function dataHandle() {
    if ( http.readyState == 4 ) {
        
        var response = http.responseText;
        document.getElementById('klok').innerHTML = response;  
    }
}

function UpdateTimer() {
	http.open('POST', 'veiling/aflopende_klok.php');
	http.onreadystatechange = dataHandle;
	http.send(document.getElementById('klok').innerHTML);
	timerID = setTimeout("UpdateTimer()", 1000);
}

function StartTijd() {			
	// Firefox, IE7, etc..
	if (window.XMLHttpRequest){


	http = new XMLHttpRequest();
	} 
	// IE 6.0, ect..
	else if (window.ActiveXObject){
	http = new ActiveXObject("Microsoft.XMLHTTP");
	} 
	timerID = setTimeout("UpdateTimer()", 1000);
}
StartTijd();

}else{


var url = 'veiling/aflopende_klok.php';


new Ajax.PeriodicalUpdater(
					'klok',
					url,
					{asynchronous:true, frequency:1, method:'get'}
                                            );
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.