R
R
r0664n2019-12-11 22:29:14
PHP
r0664n, 2019-12-11 22:29:14

Run a script on command after a certain time?

There is a script that resets the user’s product reservation if payment has not been received after a certain time, but it needs to be automated, that is, while it works, it simply checks the time, if the user executes any command in the bot, this is not correct. Cron is not suitable, since it is necessary that the script waits for a while after a certain command, after which it works. The for and sleep loops are not suitable, since the processor is loaded at 100%, are there any solutions?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
4
4iloveg, 2019-12-11
@4iloveg

Write the time to the database and run the cron every minute.
Cron looks at the time of the order at 12:00 and if the current time is 12:10 and there is no payment, then it removes the reservation (what time you need is not known, but we assume a 10-minute wait). If the cron ran the file a (current time) - (order time) < 10 then it does nothing.

#
#yamynginx, 2019-12-11
@muxui

What prevents you from doing this:
A person wrote to the bot, made a reservation.
In PHP, write (or whatever is needed for a correct answer) and write - , then write the code:echo 'ok'fastcgi_finish_request();

sleep(600); //600 секунд / 60 = 10 минут (время ожидания)
// * тут код с проверкой, была совершена оплата, или нет *

The downside of the solution is that the process will hang in the system for 10 minutes + execution time and response (with competent code optimization, this is 1-3 seconds maximum), but it will not create a load, since it will simply sleep all these 10 minutes.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question