问题描述
我们正在构建一个ajax应用程序,其中将用户输入提交到处理PHP脚本。我们目前正在将每个请求写入日志文件以进行跟踪。我想将此跟踪移动到数据库表,但我不想在请求后运行insert语句。我想做的是设置需要在MySQL数据库上处理的事务(插入和更新)的队列。然后我将设置一个cron作业或进程来检查和处理队列中的事务。有没有什么我们可以建立的,或者我们只需要写简单的文本日志文件并处理它们?
We are building an ajax application in which a users input is submitted for processing to a php script. We are currently writing every request to a log file for tracking. I would like to move this tracking into a database table but I do not want to run a insert statement after request. What I would like to do is set up a 'queue' of transactions (inserts and updates) that need to be processed on the MySQL database. I would then set up a cron job or process to check and process the transactions in the queue. Is there something out there that we could build upon or do we have to just write to plain ol' text log files and process them?
推荐答案
您希望 - 它会将请求排入队列,并在数据库准备好时将其插入
You want Gearman - it'll queue the requests and insert them as and when the database is ready for them, so you don't overload your DB server.
最近有一篇关于使用数据库记录=http://brian.moonspot.net/logging-with-mysql =nofollow noreferrer>这里,其中(总结)说:
There's a recent (and quality) post about using databases for logging here, which (summarised) says:
- 使用MyISAM并发插入
- 每天轮换表格并使用UNION查询
- 一个像Gearman这样的工作处理代理(虽然MySQL对这些代理的数量有限制,但是会默认丢弃它们。)
HighScalability 。
HighScalability write up on Gearman.
如果你真的想要避免这种情况,你可以将原始SQL语句写入一个文件,并用这个cronjob处理:
If you really want to avoid this, you could write the raw SQL statements to a file and process them with this cronjob:
mysql loggingDB logTable < fullLog.sql && > fullLog.sql
这篇关于MySQL插入语句队列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!