I've been tasked settings up the following.
6 individual stopwatches which all sync with each other. They all need to be able to start at the same time They need to be able to be stopped separately (6 people will be racing, when one finished, their timer will stop).
I'm thinking Web Sockets would be a good idea for this, so the timer can sync with the server, and I've followed this to set it up and get it running.
I'm currently at the stage where I can connect 6 individuals, and one admin page to display how many clients their are, and a "Start Timer" button.
I've created this method which i thought would send the current server time to each client every second (for 10 seconds). But it doesn't work, it sends all 10 messages at once, after 10 seconds.
private function startTimer() {
for($i = 0;$i < 10;$i++) {
$now = date('H:i:s d-m-Y');
foreach($this->all as $client) {
$client['conn']->send(json_encode(array('action' => 'time', 'time' => $now)));
}
sleep(1);
}
}
So, 1) Are Web Sockets a good way to do this, or, is Javascript/PHP not ideal for doing this project? And 2) If Web Sockets will work, how can I keep each client in sync with each other?