D
D
Dima2016-03-29 13:48:23
Database
Dima, 2016-03-29 13:48:23

How to implement? Do I need to add 1 to the database every 5 seconds?

Help me please!
How to implement?
I have a photobattle site. When the button is clicked, +1 is sent to the database.
How to make it so that every 5 seconds 1 is added to the number in the database?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
O
O. J, 2016-03-29
@OrlovEvgeny

cron is not suitable for part
except to collect and
Well, or
A already in php in a cycle with sleep's, write to the database.
There are also downsides to this approach.
- if at some point in the script execution one of the iterations (or many) is delayed a little, and in total it will be > 5 seconds per cycle, then cron will launch the second instance of the same script, despite the fact that the first one has not finished execution yet.

V
Viktor, 2016-03-29
@Levhav

It is possible to save the time of adding a record and, when selecting, add to the rating the age of the record in seconds divided by 5
Something like this:
select raate+(nowTime - addTime)/5 as traate from fotos;
And do not torment the database with a constant update of all records.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question