S
S
Sergey Semenko2015-11-16 18:45:15
PHP
Sergey Semenko, 2015-11-16 18:45:15

PHP. How to perform an action once, not earlier than the specified time?

Let's say there is a record in the database with a created_at field that contains the time the record was created. I need to make it so that, after one minute or more, the first request to the server performs an action, that is, checking for records older than one minute and then follow the instructions there. It seems nothing complicated, but if > 2 users send a request at the same time, the server simply does not have time to complete one request before another is sent and it turns out that the action is performed twice. How to deal with it?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey Petrov, 2015-11-16
@sergoslav_0

Add another field to the database, something like "status", when the first user starts the process, status is set to "process" when it succeeds "pending", if it fails "error".
And before each launch of this process, on request, check the status + time.
time > 2m + status-pending = run
time > 2m + status-error = run
time < 2m + status-pending = NO
time < 2m + status-error = run
status-processing = NO

S
Sergey, 2015-11-16
Protko @Fesor

How to deal with it?

man at

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question