I wanted to see how far PHP in WebAssembly could go. So I wrote a fan remake of Sonic the Hedgehog (Master System) entirely in PHP, about 21k lines, and made it run both natively and in the browser.
π Play it, no install: https://sonic.mimichat.fr (desktop and mobile)
How PHP runs in a browser
PHP 8.3 is compiled to WebAssembly with Emscripten, together with an SDL2 extension for PHP. A small C glue starts PHP ( php_embed_init ), runs the game, then plugs into the browser loop: on every requestAnimationFrame , one tick of the game's ReactPHP event loop.
The tricky part: ReactPHP's Loop::run() is blocking, and a browser can't allow that. So the page queues a futureTick that stops the loop right after its first turn, and the C glue then advances it one tick at a time.β¦