A six-year production case study of running a WebSocket server in PHP using ReactPHP and Ratchet. The server handles real-time event delivery for a multi-tenant CRM-like system, replacing a heavy 5-second polling mechanism. Key implementation details include: a Symfony console command as the entry point with a non-returning event loop, RabbitMQ FANOUT exchange for multi-pod event distribution using Bunny's async client, a simple connection map keyed by user ID for memory-stable state management, 60-second pings that double as sync checkpoints via lastEventId, and a periodic Monolog reset() to prevent buffer memory leaks in long-running processes. The post also covers production limits of the single-threaded event loop and compares alternatives like Swoole, FrankenPHP, RoadRunner, and SSE.

Sort: