当MySQL数据条目发生变化时有效通知
我一直在使用 HTTP POST 到 php 文件来更改给定 MySQL 数据库中的条目。本质上,当值发生变化时,我希望正在查看数据库表的用户得到通知。目前,我的临时解决方案是自动刷新显示表格的页面以保持其更新,但我觉得必须有一种更有效的方法来解决这个问题。
I've been using an HTTP POST to a php file to change entries in a given MySQL database. Essentially, the second the value changes, I would like the user that is viewing the database table to be notified. For now my temporary solution is to auto refresh a page displaying the table to keep it updated but I feel like there has to be a more efficient way of going about this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
IIRC mysql_affected_rows() 只会报告数据已更改的实例(即,如果您尝试将行更新为其当前值,则不会给出错误)。
我发现很难相信有人看着屏幕等待更新发生 - 也许更好的方法是在记录中添加时间戳字段 - 但请注意,如果您这样做,并且在没有其他检查时,记录将始终更新 - 以防止确保至少有一个字段在更新中已更改。
C.
IIRC mysql_affected_rows() will only report instances where the data has changed (i.e. if you try to update a row to its current values then it won't give an error).
I find it hard to believe that you've got someone watching a screen waiting for an update to occur - maybe a better approach would be to add a timestamp field to the record - but note that if you do this, and in the absence of other checks, the record will always update - to prevent make sure at least one of the fields has changed in the update.
C.
当我必须这样做时,我创建了一个单行表,其中包含上次更新数据库的任何相关部分的时间。然后,每秒一次的活动仅限于查看该单行表的内容是否显示比本地值更新;如果是,请刷新。
单行表可以通过包含相关事实的任何表或应用程序的触发器进行更新,只要您认为最好。
When I had to do this, I created a one-row table containing the last time any relevant part of the database was updated. Then the once-per-second activity was confined to seeing if the contents of that one-row table showed newer than the local value; if so, refresh.
The one-row table could be updated via triggers from any table containing relevant facts, or from the application, as you think best.
签出 pines notification 我将它与 ajax 提交的更改一起使用
checkout pines notify i use it with ajax submitted changes
我们使用incrontab和curl来监视数据库表文件,例如/var/lib/mysql/database/table.MYD,并在IN_MODIFY上向客户端服务器发出http请求。效果很好。
We use incrontab and curl for monitoring database table files, like /var/lib/mysql/database/table.MYD, and fire a http request to the client servers on IN_MODIFY. Works very well.
你真的必须在同一秒更新它吗?它看起来像是一个服务器杀手功能。
阅读Comet,也许会有用。
Do you really have to update it in the same second? It looks like a server killer feature.
Read about Comet, maybe it will be useful.