gpt4 book ai didi

php - 如何使用 jQuery、PHP 和 MySQL 实现聊天?

转载 作者:塔克拉玛干 更新时间:2023-11-03 06:04:31 24 4
gpt4 key购买 nike

我使用 php、mysql 和 jquery 制作了一个聊天脚本。它使用 json 从服务器获取数据。它使用最后获取的消息 ID 向服务器发出固定间隔请求,以从服务器获取新消息。但是,当多个用户聊天时,将在一个小时内向服务器发出成千上万的请求,而托管人员肯定会阻止它。

我认为 gmail 聊天使用套接字。因为它肯定不会发送固定间隔的请求。你们中的任何人都可以给我一些示例代码或一些指导来解决这个问题。

拜托,我急需帮助。

非常感谢。我对所有人的尊重和问候。

最佳答案

如果您使用的主机在发出那么多请求时会“肯定地阻止它”,那么您可能需要考虑换一个主机或升级您的托管包,然后再担心您的代码。查看如何 Facebook implements their chat:

The method we chose to get text from one user to another involves loading an iframe on each Facebook page, and having that iframe's Javascript make an HTTP GET request over a persistent connection that doesn't return until the server has data for the client. The request gets reestablished if it's interrupted or times out. This isn't by any means a new technique: it's a variation of Comet, specifically XHR long polling, and/or BOSH.

关于php - 如何使用 jQuery、PHP 和 MySQL 实现聊天?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/603046/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com