Examples menu

Type Race multiplayer

Join a race and type the PHP snippet faster than the other visitors. Each race is a custom scope, and every keystroke updates progress and WPM for all racers.

Race state machine: each race moves through waiting, countdown, racing and done. All transitions happen server-side; the client just sends keystrokes.
Custom scope per race isolates each race's broadcasts. Multiple races can run simultaneously. Joining players are routed to an open race automatically.
Progress is server-computed: the client sends only the latest typed text; the server counts matching leading characters against the snippet. No snippet logic ships to the browser.
Countdown timer: an OpenSwoole Timer::tick() per race counts 3…2…1 and broadcasts to all racers each tick. WPM comes from the time since the start.
SESSION identity gives each racer a persistent name across tabs and refreshes. Joining the same race twice from two tabs counts as two racers.
Anti-cheat by design: the server holds the snippet truth and computes every progress value. Sending the wrong text just gives zero progress.
One worker: this demo keeps the races in PHP statics, which each worker holds on its own. See What stays per worker before you run it with withWorkerNum().

Waiting for racers…

Click Start race when everyone is ready. Open this page in another tab to race yourself.

Lynx94 (you)

Signals

username string session scope

Racer handle, auto-assigned. Persists across tabs.

typedText string tab scope

Current textarea value. Sent to server on every input event; never broadcast. The server clears it when a race starts.

Actions

updateProgress

Called on every input event. Server counts correct leading chars, updates this racer's progress and WPM, broadcasts to race scope.

startRace

Starts the countdown of the race this tab waits in.

newRace

Resets a finished race with a new snippet and pulls in racers waiting alone in another lobby.

Views

type_race.html.twig

Lobby, countdown overlay, racing textarea + progress bars, and results podium. The race's status, kept on the server, picks the panel.