Y
Y
Yustas Alexu2014-07-08 18:15:53
linux
Yustas Alexu, 2014-07-08 18:15:53

How to make a reverse report on the server through php?

Let's say the user has made some action, the server starts the countdown. Something like setTimeout on the server only. At the end of the countdown, you need to take a certain action if there is a certain condition (an entry in the database). For example, run the php.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
D
Dmitry Entelis, 2014-07-08
@DmitriyEntelis

php is focused on the "as soon as possible give the answer to the client and die" paradigm, it does not have an event model.
Accordingly, there is no analog setTimeout there.
There is a sleep function, but using it in this perspective is barbaric.
If you need to process some kind of timeout, the correct solution is to enter these timeouts into some kind of table for further processing, and process expired cron tasks for example.

V
Vladlen Grachev, 2014-07-08
@gwer

Purely on the server - add a task to cron. The script executed by cron first checks the condition, on the basis of which it decides whether to continue executing or not (well, or calls / does not call another script).

E
Egor Ogurtsov, 2014-07-08
@mrdubz

And why consider time puff? Send a timestamp to the server and read it on the client, and then verify and perform other actions.

I
Ilya Lesnykh, 2014-07-09
@Aliance

I am currently implementing something similar. I do this:
- the timestamp of the beginning of the countdown is written in the storage (+ we have the number of minutes of the timer countdown)
- we send to the client how many seconds are left before the timer ends using the timestampFromStorage formula - nowTimestamp
timestamp is pointless to send to the client, because local time can be set any.
Of the minuses of this approach, it will be that the transfer from the server to the client takes some time, for which time we will have the client late.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question