I want to design central control timer with php and any other client side script.
the basically things that need to keep in mind is that : timer will be visible on my website,so may be hundred of user are currently logged in to my website. Now whenever admin reset the timer on the same point it should reflect to all the client machine. so basic is need to keep synchronous timing all the machine.
What I did
I have used client side countdown timer (http://keith-wood.name/countdown.html) and in background I am calling ajax on every second to check reset is pressed or not. but the problem is its not keeping synchronous in all the client machine. some time time gape between two machine is marked.so how to implement it?
code:
$('#shortly').countdown({until: shortly,
onExpiry: liftOff, onTick: watchCountdown});
$('#shortlyStart').click(function() {
shortly = new Date();
shortly.setSeconds(shortly.getSeconds() + 5.5);
$('#shortly').countdown('option', {until: shortly});
});
function liftOff() {
alert('We have lift off!');
}
function watchCountdown(periods) {
$('#monitor').text('Just ' + periods[5] + ' minutes and ' +
periods[6] + ' seconds to go');
}
Try this instead, using HTML5's server-side-events.
on the server, and
on the client (asuming the server file is in the same folder and is called 'gsim_server.php'. This is just a basic example, but you could use the value passed to decide wether to reset or not. Hope that helps.
timerset.php. This file creates the file for the server side to push the finish time.
timer.php. This file receives the finish time and updates the displayed time.
timerform.php . One method of updating the time.
NB, Use UTC time to cater for different clients in different timezones.
I have the above code working on both my localhost (Windows) and at SouthCoastHosting (Linux), so let me know if you have any problems.
To use it open a tab to southcoasthosting.com/timer/timerform.php and another tab to southcoasthosting.com/timer/timer.php. Use the timer form to change the finish time and you will see the time chage in timer.php. Due to the nature of EventSource there will always be at best a 3 second delay before updating the timer. Depending on your clients connection speed to the server there may be further delays. I chose to send a finish time so that the client will not lag due to these delays.
I hope that all makes sense. Let me know otherwise.