Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP server side timer?

Tags:

php

timer

I want to create a single timer that is displayed on my site, I want for it to be synchronous across all clients trying to access it. When a client clicks the "increase" button, I want the timer to add 1 minute to the countdown and I want this change to be reflected for all clients.

Is this achievable through PHP? Any tips/advice to get me started?

Thank you!

like image 385
101010110101 Avatar asked Nov 15 '22 06:11

101010110101


1 Answers

If you want a click from any client to effect all clients you will need to base the solution either on Polling (refreshing an AJAX hit) or Comet programming. A comet programming solution is more complex, but allow you to push the timer updates to all the clients in real time.

Word of Advice: Unless your website is planning on doing a large amount of asynchronous communication, I'd just stick with a simple polling solution. You could even have the AJAX poll a static file and update the static file via PHP (this updating needs to be done atomically). This means each AJAX poll will be very cheap.

like image 92
Kendall Hopkins Avatar answered Nov 17 '22 06:11

Kendall Hopkins