A
A
Alex Pro2022-03-05 08:54:26
PHP
Alex Pro, 2022-03-05 08:54:26

Chronograph/countdown timer on the web?

Good day, please help! It is required to create a chronograph / countdown timer on the web. It is not yet clear how and why.
The meaning is this:
There is a countdown timer starting 60 seconds and up to 0 or from 120 seconds to 0.
There is a control - start / pause / reset and 2 or 1 minute
This timer should work on any clients (browsers) synchronously. Those launch in one place and the data at all, and at the same time, this timer needs to be embedded (displayed) on different pages.
Those start the timer on the page ( 10.0.0.1/timer ) and on the Tableau page ( 10.0.0.1/tablo ) and others, this timer is displayed with the same time and the ability to control (start / pause)
The usual timer on the client is understandable. But how to do this and how, is not yet clear.
Previously, using websocket + js, I kicked on php, but everything was complicated and worked poorly and so on.
Where to dig, what to read, how is it even possible to write??? Can with a DB can what other tools??

Thank you!

scheme of work:6222fac2a50fb095847572.png

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Aetae, 2022-03-05
@Aetae

On the server, you save the start date (server) at the first call and return how much is left.
On subsequent calls, you take the current date on the server from anywhere and subtract the starting date from it, after which you return how much is left.
On the client, you get the remainder and show a regular timer with this number running in client time.
Everything.
No constant swotting of the server and synchronization is needed if the user has no problems with the clock. If there is (the chance of which is negligible) - then these are his problems, the server knows the exact date early.

A
Alexander Kubintsev, 2022-03-15
@akubintsev

I think you can safely limit yourself to the centrifugo + php-fpm server stack.
When the page loads, it connects to the centrifuge and subscribes to the timer notification channel.
During start/stop/pause operations, a request is sent to the backend. The backend does the necessary commit logic and sends a notification to the centrifuge in the notification channel so that the clients react accordingly.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question