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 al开发者_StackOverflowl clients.
Is this achievable through PHP? Any tips/advice to get me started?
Thank you!
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.
Yes it can be done, but you need some delayed AJAX, the same technology used to created javascript chat windows, realtime logging etc.
精彩评论