PHP MySQL 和队列、表锁定、读写器问题
我有以下场景:
PHP(Server, Writer) ----> MySQL Database <------ PHP(Client, Reader/ Writer);
- PHPS = PHP 服务器
- PHPC = PHP 客户端
它是如何工作的?
- PHPS 将数据写入临时数据库表 (queue_*)。
- PHPC 由 1 小时的 cron 触发。
- PHPC 启动,连接到数据库并在本地缓存所有记录(如何?不知道,本地 mysql db?sqlite?)
- PHPC 逐一执行这些记录中定义的任务
- 如果任务成功,则会将其从数据库中删除
- 如果不成功,它会将该记录添加到数据库中的报告表下。
我如何实现这一点
- 没有从 PHPS 到达 PHPC 的半写入记录。
- PHPC 可以在一次查询处理后将所有记录缓存在本地。
如果您有任何其他想法并分享,我们将不胜感激。
I have following Scenario:
PHP(Server, Writer) ----> MySQL Database <------ PHP(Client, Reader/ Writer);
- PHPS = PHP Server
- PHPC = PHP Client
How it works?
- PHPS writes data to temporary database tables (queue_*).
- PHPC is triggered by a 1 hour cron.
- PHPC starts, connects to database and caches all records locally (how? no idea, local mysql db? sqlite?)
- PHPC executes tasks defined in those records one by one
- if the task is successful it removes it from databases
- if its unsuccessful it adds that record in database under a reports table.
How do i implement this such that
- No half written records from PHPS get to PHPC.
- PHPC can cache all records locally after one query to process them.
Any other ideas that you might have and share are highly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
MySQL 的默认锁定将确保不会获取“半写”行。至于“本地缓存”,在您的场景中似乎意味着将它们从数据库中读取到本地 PHP 数据结构(如数组)中。
MySQL's default locking will ensure that no "half-written" rows are fetched. As far as "caching locally", it seems like all that means in your scenario is reading them out of the database into a local PHP data structure like an array.
您可以在这里查看有关 MySQL 锁定的信息: Locking in MySQL 。写入数据完成后记得解锁表。
you can see about MySQL locking here: Locking in MySQL. Remeber unlock table after finishing write data.