What is Long-Polling, WebSockets, SSE and Comet? How to implement in PHP?
Hello everyone! I'm a beginner PHP developer writing a simple chat on a website. Currently it works like this: a user sends a message via AJAX, it's saved to the database, and other users manually refresh the page (F5) to see new messages. This is terribly inconvenient!\n\nI've heard there are technologies for "real-time": Long-Polling, WebSockets, SSE and Comet. But I'm confused about the terms. As I understand, Comet is not a technology at all, but a pattern?\n\nI need new messages to appear for all users immediately, without reloading the page. I'm using PHP 8.2, Apache and MySQL. Tell me which approach to choose for a chat? I tried a simple solution with setInterval() every 2 seconds, but the server starts to lag with 20 users.\n\nHere's a piece of my current code (checking new