Hello community,

I am reaching out on behalf of the WasmLabs team at the Office of the CTO at 
VMware.

We have been working on building PHP for WebAssembly, specifically for the 
wasm32-wasi target. WASI [1] is a system interface that allows WebAssembly to 
run on the server side by safely being able to access operating system-like 
features, including files and filesystems, Berkeley sockets, clocks and random 
numbers [2].

WebAssembly in the server side is experiencing a big growth both in interest 
and users. There are other programming language interpreters that can be 
compiled to wasm32-wasi as of today; for example: Python [3] and Ruby [4].

We have patches for PHP 7.3.33 and 7.4.32 at the time of writing. Porting PHP 
8.2.0 is work in progress at this time.

In the interest of getting feedback from the PHP community I am providing links 
to the patches at GitHub. Please, let us know what would be the next step to 
contribute and continue to maintain this work upstream. We look forward to work 
with the PHP community.

If you want to try it out, you can download the binaries we are producing in 
the CI/CD pipeline for 7.3.33 [5] and 7.4.32 [6]. You can use a WASI-enabled 
WebAssembly runtime such as Wasmtime [7] to run PHP compiled to wasm32-wasi.

Patches: 7.3.33 [8], 7.4.32 [9][10].

Example execution:

```
$ wasmtime -- --dir ~/php-example php-cgi-7.4.32.wasm 
~/php-example/hello/index.php
X-Powered-By: PHP/7.4.32
Content-type: text/html; charset=UTF-8

Hello, world!
```

We have already presented some of this work at OSS conferences and events like 
Kubecon and Docker Community days, and have written a few articles providing 
the background to the port, its limitations and what can currently be 
accomplished (including running WordPress!). Please find below some links to 
the talks and articles:

- Porting PHP to WebAssembly using WASI  [11]
- Running WordPress with WebAssembly using mod_wasm and Apache  [12]
- WebAssembly: Docker without containers! [13]
- mod_wasm: Bringing WebAssembly to Apache [14]: this talk builds on top of PHP 
7.3.33 and shows WordPress running with sqlite on top of Apache, thanks to an 
Apache module (mod_wasm) that is able to execute WebAssembly modules.
- Docker and WebAssembly, better together [15]: this presentation features PHP 
7.4.32 and explains a bit of the context of this work.


Thank you,
Rafael Fernández López.

[1] https://wasi.dev/
[2] 
https://github.com/bytecodealliance/wasmtime/blob/03463458e426d4bd0601ebd82e95b668fc982443/docs/WASI-intro.md
[3] https://docs.python.org/3/whatsnew/3.11.html
[4] https://www.ruby-lang.org/en/news/2022/12/06/ruby-3-2-0-rc1-released/
[5] 
https://github.com/vmware-labs/webassembly-language-runtimes/releases/tag/php%2F7.3.33%2B20221124-2159d1c
[6] 
https://github.com/vmware-labs/webassembly-language-runtimes/releases/tag/php%2F7.4.32%2B20221124-2159d1c
[7] https://wasmtime.dev/
[8] 
https://github.com/vmware-labs/webassembly-language-runtimes/tree/main/php/php-7.3.33/patches
[9] 
https://github.com/vmware-labs/webassembly-language-runtimes/blob/main/php/php-7.4.32/patches/0001-Initial-port-of-7.3.33-patch-to-7.4.32.patch
[10] 
https://github.com/vmware-labs/webassembly-language-runtimes/blob/main/php/php-7.4.32/patches/0002-Fix-mmap-issues.-Add-readme.patch
[11] https://wasmlabs.dev/articles/php-wasm32-wasi-port/
[12] https://wasmlabs.dev/articles/running-wordpress-with-mod-wasm/
[13] https://wasmlabs.dev/articles/docker-without-containers/
[14] https://www.youtube.com/watch?v=jXe8kulUscQ
[15] https://youtu.be/yo30oF1Gflo?t=7361

Reply via email to