开发者

PHP server side timer?

开发者 https://www.devze.com 2023-01-19 18:49 出处:网络
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 a

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消