PHP即时通讯方法

发布于 2024-11-14 08:57:40 字数 1432 浏览 4 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

深海夜未眠 2024-11-21 08:57:40

最常用的方法称为 COMET

这是一个 PHP 实现: How to Implement COMET with PHP

在 HTML5 规范中有一些内容称为 websockets,许多浏览器已经实现了。下面是一个支持 websocket 的 PHP 项目:phpwebsocket。如果浏览器不支持 websockets(因此向后兼容),有一些 javascript 库可以使用 flash 组件,

恕我直言,websocket 是最佳选择,尽管 PHP 可能不是最适合处理它们的后端。

The most frequently used method is called COMET.

Here is a PHP implementation: How to implement COMET with PHP

In the HTML5 specification there are something called websockets that many browsers already have implemented. Here is a PHP project supporting websockets: phpwebsocket. There are some javascript libraries which can use a flash component if the browser do not support websockets (and therefore be backwards compatible)

imho webSockets is the way to go, although PHP might not be the most suitable backend to handle them.

故事与诗 2024-11-21 08:57:40

如果您知道如何使用Socket,那么就使用它们;否则,只要不需要实时,在计时器中使用 AJAX 就足够了(获取消息之间有 5-10 秒的延迟应该可以)。

If you know how to use Sockets then use them; otherwise using AJAX in a timer should suffice so long as it doesn't need to be real-time (5-10 second delays between fetching messages should be OK).

南风几经秋 2024-11-21 08:57:40

我建议为此使用 Socket.IO。

I'd suggest using Socket.IO for this.

爺獨霸怡葒院 2024-11-21 08:57:40

PHP 有几个选项:

  1. 正如 @jgauffin 所指出的,您可以使用 Comet 使用 Comet 和 PHP 选项 或 WebSocket使用 phpwebsocket 之类的解决方案。
  2. 您可以创建另一个专用于处理实时消息传递的组件,例如在现有主机或完全专用的服务器上运行的专用 Comet 或 WebSockets 进程。如果您采用这种方法,您可以考虑使用在 Node.js 或完整的第三方 Comet 中运行的 socket.io 之类的东西,或者WebSockets 服务器。
  3. 最后,您可以查看托管服务,该服务允许您保留现有的开发和生产环境,然后您可以进行实时聊天。其中一项名为 Pusher(我从事的工作)的服务除了提供专门开发的附加功能外,还处理所有实时消息传递基础设施使聊天应用程序易于构建。这也意味着,如果您使用的是共享主机之类的东西,那么您不需要升级主机,因为共享主机的内容被严格锁定,并且您无法轻松安装自己的组件。

You have a few options from PHP:

  1. As pointed out by @jgauffin you could look doing this on your existing PHP server using a Comet using the Comet and PHP option or WebSocket Solution using something like phpwebsocket.
  2. You could create another component dedicated to handling your real-time messaging such as a dedicated Comet or WebSockets process running on you existing hosting or a wholly dedicated server. If you take this approach you could look at using something like socket.io running in node.js or a full third party Comet or WebSockets server.
  3. Finally, you could have a look at a hosted service which would allow you to keep your existing development and production environment and you could then layer on the real-time chat. One such service called Pusher (which I work on) handles all the real-time messaging infrastructure in addition to providing added functionality specifically developed for making chat applications easy to build. It also means that you don't need to upgrade your hosting if you are using something like shared hosting where things are tightly locked down and you can't easily install your own components.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文