101010110101
101010110101

Reputation: 2000

PHP server side 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!

Upvotes: 5

Views: 1913

Answers (2)

Kendall Hopkins
Kendall Hopkins

Reputation: 44104

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.

Upvotes: 1

CMartins
CMartins

Reputation: 1

Yes it can be done, but you need some delayed AJAX, the same technology used to created javascript chat windows, realtime logging etc.

Upvotes: 0

Related Questions