PHP/Mysql中的动作侦听器,何时将任何记录插入表中? [英] Action Listener in PHP/Mysql, whenever any record inserted into table?

查看:45
本文介绍了PHP/Mysql中的动作侦听器,何时将任何记录插入表中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们知道他们的任何方法/方式吗,所需表中是否有任何更改?

Is their any method/way that we come to know, any change occurs in desired table?

我已经实现了一种解决方案,它每30秒检查一次db,也就是说,如果chats表中发生任何更改,请刷新我的chats列表.它会降低性能,并拖慢网站的速度.

I have implemented one solution that it checks in db every 30 sec, that is if any change occur in chats table then refresh my chats listing. it waists lot of performance and slow down the site.

我们的操作侦听器是否仅在表中插入任何行时调用它们的任何方式?

Is their any way that our action listener only calls whenever any row is inserted in table?

有什么主意吗?

推荐答案

您可以创建带有通知的表(该表将始终仅包含最近2个小时左右的未读消息),然后创建

You may create table with notifications (which will always contains just unread messages for last 2 hours or so) and then create trigger [syntax] that will create new notification each time change occurs:

CREATE TRIGGER create_notification AFTER INSERT ON chats
FOR EACH ROW INSERT INTO notifications (...) VALUES( NEW.col1, NEW.col2)...

然后,您将获得更小(并且更快)的数据库表.

Then you'll end up with much smaller (and faster) database table.

还有一些替代方法,例如编写套接字服务器,但我认为这将比池化数据库的资源效率低,而且我长期运行php脚本的经验很差.

There are some alternatives like writing a socket server but I think it would be less resource effective than pooling database plus I have a bad experience running php scripts for a long time.

这篇关于PHP/Mysql中的动作侦听器,何时将任何记录插入表中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆