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'}
                                            );
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.