query table every second for notification. Is it a good practice?(每秒查询表以获取通知.这是一个好习惯吗?)
问题描述
我有一个具有通知功能的项目,我想出了一个关于如何实时获取通知的想法.我的想法是每秒查询一次表.我有一个通知表,所以每当客户端添加一些东西时,它都会插入到通知表中,然后另一个客户端通过查询来获取通知.我使用 ajax 来做到这一点.
I have a project that has notification functionality and I came up with an idea on how to get a notification real time. My idea is to query the table every second. I have a notification table, so whenever the client is adding something it will insert to the notification table and then the other client gets the notification by querying it. I use ajax to do this.
每秒查询一次表是好还是不好的编程习惯?我只在 localhost 中使用它,这很好.当网站上线时,这种想法会产生负面影响吗?
Is it good to query the table every second or it's bad programming practice? I only use this in localhost and it's fine. Do this kind of idea affect negatively when the site goes live?
预先感谢您的回答.
推荐答案
每秒 ping 一次数据库并不是实现此目的的理想方式;您可以实现数据库触发器和 HTML5 websockets/推送通知的组合:http://html5hacks.com/blog/2013/04/21/push-notifications-to-the-browser-with-server-sent-events/
Pinging the DB every second is not the ideal way to do this; you can implement a combination of DB triggers and HTML5 websockets/push notifications: http://html5hacks.com/blog/2013/04/21/push-notifications-to-the-browser-with-server-sent-events/
http://www.abrandao.com/2013/06/25/websockets-using-modern-html5-technology-for-true-server-push/
http://pusher.com/tutorials/html5_realtime_push_notifications
这篇关于每秒查询表以获取通知.这是一个好习惯吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:每秒查询表以获取通知.这是一个好习惯吗?
基础教程推荐
- 学说 dbal querybuilder 作为准备好的语句 2022-01-01
- 在PHP中根据W3C规范Unicode 2022-01-01
- PHP PDO MySQL 查询 LIKE ->多个关键词 2021-01-01
- 如何在 Laravel 5.3 注册中添加动态下拉列表列? 2021-01-01
- 如何在 Laravel 中使用 React Router? 2022-01-01
- 如何替换eregi() 2022-01-01
- PHP 类:全局变量作为类中的属性 2021-01-01
- Cron Jobs 调用带有变量的 PHP 脚本 2022-01-01
- YouTube API v3 点赞视频,但计数器不增加 2022-01-01
- 有什么方法可以用编码 UTF-8 而不是 Unicode 返回 PHP`json_encode`? 2021-01-01
