简体   繁体   English

PHP & MySQL:检查表的数据是否在没有轮询的情况下发生了变化?

[英]PHP & MySQL: Check if table's data has changed without polling?

Is there a way to test if a MySQL table's data has changed at all , without connecting or querying.有没有一种方法可以测试 MySQL 表的数据是否发生变化,而无需连接或查询。

This might sound weird, but in ASP.NET you can set up SqlDependencies that are kind of events that occur when data is changed (so you don't have to poll your database).这听起来可能很奇怪,但在 ASP.NET 中,您可以设置 SqlDependencies,它们是在数据更改时发生的一种事件(因此您不必轮询数据库)。

you can use a UDF inside of a trigger to send a message through a socket.您可以在触发器内使用 UDF 通过套接字发送消息。 if you can not develop your own udf then maybe a combination of sys_exec and telnet will do the trick.如果您不能开发自己的 udf,那么也许 sys_exec 和 telnet 的组合就可以解决问题。

but be careful and do a good exception handling ie socket timout.但要小心并做好异常处理,即套接字超时。

Might not fit your solution (especially if the writer to the db is not in the same application space as the reader) but what if on insert, you set some application wide variable to a Last updated value.可能不适合您的解决方案(特别是如果数据库的编写者与读取器不在同一个应用程序空间中),但是如果在插入时,您将一些应用程序范围的变量设置为 Last updated 值。
Which avoids you polling the db directly, although, there may still be some polling of the application for that value.这避免了您直接轮询数据库,但可能仍然会对该值的应用程序进行一些轮询。

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

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