The blog

A New Contribution to PHP: Running Examples with PHP Wasm

Published on December 09, 2024

Antoine "Soyuka" Bluchet has recently enhanced the PHP website by integrating a feature that allows code examples to be executed directly in the browser. This achievement represents both a first iteration and the culmination of several months of work he has dedicated to this project. Antoine had previously presented the early stages of these developments at various conferences.

PHP web browser" class="wp-image-10437#

What is WebAssembly 

WebAssembly (often abbreviated as Wasm) is an open standard designed to execute compiled code quickly and efficiently in web browsers. It is portable to other environments and delivers performance close to that of native applications. Many programming languages, such as Go and Rust, now have WebAssembly compilers.

To compile PHP into WebAssembly, Antoine used emscripten (an LLVM-based toolchain, commonly used in PHP's compilation processes), enabling it to be used as a PHP sandbox running directly in the web browser. He had already demonstrated the feasibility of such usage during SymfonyCon Brussels 2023.

#

An initial experiment with API Platform

Since version 3.2, API Platform has offered a playground mode that allows the framework to run in the browser using WebAssembly. Antoine presented the ins and outs of this work during API Platform Con 2023. You can also find more details on his blog in a dedicated article: “How to create a PHP Playground for your documentation · soyuka.me.”

#

A Constant Collaboration with the PHP Foundation

Antoine’s contribution is part of our broader commitment to the PHP Foundation, a nonprofit organization dedicated to supporting and promoting the development of the PHP language. Supporting this foundation has a significant impact on the PHP ecosystem: it helps ensure the language’s longevity by enabling the core team to maintain high-quality support while fostering innovation and introducing new features — as exemplified by this contribution. You can find the few lines of code behind this feature on GitHub.

What do you think about this new feature? Have you tried it? Feel free to share your feedback with us!

The blog

Go further