Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想让服务器知道客户端何时断开连接。因此,我想实现长轮询。问题是:循环的简单解决方案会消耗大量资源,但我不知道更好的方法。
如果您想远离 WebSocket,这里有一个解决方案:
让客户端每 2 秒左右用一个唯一的 id ping example.php。
example.php 会这样做: