Better HN
topnewbestaskshowjobs
Log inSign up

bencroker

7 karma · joined Apr 11, 2025 (1y ago) · 3 submissions

Submissions

comment 1y ago · link · parent

Definitely something I want to explore! For this demo in particular, I wanted to stick with native PHP tooling and Redis (ubiquitous in the PHP ecosystem).

Have yet to look into making Mercure work with Datastar’s SSE events, have you done so?

comment 1y ago · link · parent

Agreed! I have a WIP article in which I describe in the setup in more detail. I’ll also include load testing benchmarks as part of it. The key to reaching high scale is keeping things simple, and there’s really very little that the app is doing. Swoole and Redis are doing the heavy lifting, and they’re both heavily optimised for scale out-of-the-box.

comment 1y ago · link · parent

My goal with this demo was to build a real-time, multiplayer app that can scale to thousands of concurrent, long-lived connections. Using PHP.

Laravel Octane keeps the bootstrapped app loaded in memory, which can scale to thousands of requests per second for the toggling of cells. A separate script starts a Swoole HTTP server to make async I/O work in PHP for serving long-lived SSE connections. The event stream is compressed using gzip by the web server (standard Nginx). The app uses Redis pub/sub for real-time messaging, and a Redis key-value store for state persistence. Rate limiting on the server helps prevent automated bots causing too much havoc.

Finally, reactivity is powered by Datastar with one event listener and one long-lived SSE connection to the backend.

It all runs on a €4 Hetzner VPS.