php中类似facebook的通知系统

2022-01-06 00:00:00 database notifications php javascript ajax

我怎样才能建立一个类似 facebook 的通知系统:- 用户 A 向用户 B 写一条消息- 数据库上的侦听器将消息路由到 userB- 在userB界面,消息立即出现

How can I put in place a facebook-like-notification system: - A userA writes a message to the userB - A listener on the database routes the message to the userB - On the userB interface, the message appears instantly

我怎样才能在 php 中做到这一点?

How can I do that in php?

非常感谢,

问候

推荐答案

我不建议使用轮询或尝试使用 PHP 实现基于推送的解决方案,如果您将有任何可观的流量.发生的情况是,最终所有 PHP 进程都被阻止,然后您就无法再处理 Web 请求.

I wouldn't advise using either polling or trying to implement a push based solution using PHP, if you are going to have any sizable traffic. What happens is that eventually all the PHP processes get blocked, and then you can't serve anymore web requests.

查看 node.js、cometd 或其他基于推送的解决方案.如果您需要一些简单的东西并且需要快速启动和运行,我建议您使用 http://pusherapp.com/.他们有可用的 PHP 客户端和超级简单的 API.

Look into node.js, cometd or another push based solution. If you need something simple and need to get up and running quickly, I'd recommend http://pusherapp.com/. They have a PHP client available and super simple API.

相关文章