简体   繁体   English

使用 php 监控 mysql 变化 **WITHOUT** 轮询

[英]using php to monitor mysql changes **WITHOUT** polling

I have seen many questions similar to the one I asked.我见过很多与我问过的问题类似的问题。 A few of them said that its ok to poll, and that doesn't affect the database performance significantly, and some are still unanswered.有几个说可以轮询,对数据库性能影响不大,有的还没有回答。 What I want to know is this :我想知道的是:

  • Can I do something similar to ASP.NET's sqldependency, which helps to find out when changes are made to the database WITHOUT polling.我可以做一些类似于 ASP.NET 的 sqldependency 的事情,它有助于找出何时对数据库进行了更改而无需轮询。
  • I know polling is ok to do, might not affect database performance, but I need to know the update as soon as it is made, so I feel I need something better than just polling every 1 second.我知道轮询是可以的,可能不会影响数据库性能,但是我需要在更新后立即知道更新,所以我觉得我需要比每 1 秒轮询一次更好的东西。
  • As an add on point, the updates that are detected at the server then have to be pushed (Ajax Push - I'm using Ajax Push Engine) to all the clients who are subscribed to a particular channel.作为补充,在服务器上检测到的更新必须被推送(Ajax 推送 - 我正在使用 Ajax 推送引擎)到订阅特定频道的所有客户端。

Thanks & Regards, Thothathri Srinivasan感谢和问候, Thothathri Srinivasan

Redis PubSub Redis 发布订阅

I hoped triggers could help you out, but after a little examination I (highly) have my doubts.我希望触发器可以帮助你,但经过一些检查后我(高度)有我的怀疑。

You could achieve your goal using Redis pubsub .您可以使用Redis pubsub实现您的目标。 Redis is an extremely fast data structure server . Redis 是一个极快的数据结构服务器 Publish the database changes to a channel and let the interested clients detect the changes by subscribing to that same channel(in real-time).将数据库更改发布到频道,并让感兴趣的客户端通过订阅同一频道(实时)来检测更改。

Downloading/Installing Redis is really easy and as extra bonus you will also "get an open source, advanced key-value store. It is often referred to as a data structure server since keys can contain strings, hashes, lists, sets and sorted sets."下载/安装Redis 非常简单,作为额外的奖励,您还将“获得一个开源的高级键值存储。它通常被称为数据结构服务器,因为键可以包含字符串、散列、列表、集合和排序集合.”

Installing it is probably the best way, but if you can't, you could use the free http://redistogo.com plan to talk the Redis server with the limitation that you will only get 5MB to store your data and that it will not be persisted to disc.安装它可能是最好的方法,但如果你不能,你可以使用免费的http://redistogo.com计划来讨论 Redis 服务器,限制你只能获得 5MB 来存储你的数据,并且它会不会被持久化到磁盘。

您可以将服务器推送与 websockets 或 Comet 之类的实现结合使用。

I like Alfred's pubsub idea.我喜欢阿尔弗雷德的 pubsub 想法。 I would think about the database as a subscriber to the insert events, not as the canonical version.我会将数据库视为插入事件的订阅者,而不是规范版本。 Maybe this isn't possible with your existing codebase.也许这在您现有的代码库中是不可能的。 You might also be able to monitor the binary logs on the database server to watch changes come in and push this information to the subscribers.您还可以监视数据库服务器上的二进制日志以观察更改并将此信息推送给订阅者。

我认为 Q4M 正是你想要的http://q4m.github.com/tutorial.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM