Database delay Delay Voting
I made a voting project, do not want to every vote to visit the update database, want to update the database after a certain time, how should I do?
Reply to discussion (solution)
If the database is not updated immediately after the poll, does the result of the poll appear incorrect?
Real-time functionality, no need to bulk INSERT.
If the database is not updated immediately after the poll, does the result of the poll appear incorrect? I think it's a minute. Update database
The more straightforward way I can think of is:
Writes the result of the poll to a text file, either as an SQL statement (recommended) or as a simple dump of the data.
Run a cron job in the background, scan the software every minute, and filter what needs to be updated to the database with some markup (such as the maximum Id,timestamp last processed).
The voting results can be divided into an array of time periods, the array to write a temporary file, every time to extract the file, and then empty the file, with the 4 floor of the idea of the same!
Use the queue now! This should be very convenient, real-time data is also convenient ~
How about using caches like memcache?
Bulk read and write to database at a time and empty memcache
Make a B, write the data into table B, partition time to update the B data to a inside.
and 4 5, 7 floors. Create a temporary file store and then read it to the library in time.
Write to file and save to database?
So what's the use of a database?
I suggest you write the database directly.
The concurrency of a file is actually not good to handle.
And from the point of view of reading files and databases, I think the database is more convenient
The database is doing this. Your project is a very small project.
The MySQL memory table processes the data.
The more straightforward way I can think of is:
Writes the result of the poll to a text file, either as an SQL statement (recommended) or as a simple dump of the data.
Run a cron job in the background, scan the software every minute, and filter what needs to be updated to the database with some markup (such as the maximum Id,timestamp last processed).
That's what I'm doing with this idea.
The voting results can be divided into an array of time periods, the array to write a temporary file, every time to extract the file, and then empty the file, with the 4 floor of the idea of the same!
What do you mean by extracting files every once in a while? PHP programs are triggered to run after the bar, how can you automatically extract this file every time?