Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:119212 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 34747 invoked from network); 28 Dec 2022 13:16:07 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 28 Dec 2022 13:16:07 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 5BC2E1804F7 for ; Wed, 28 Dec 2022 05:16:04 -0800 (PST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HTML_MESSAGE, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from mail-pf1-f172.google.com (mail-pf1-f172.google.com [209.85.210.172]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Wed, 28 Dec 2022 05:16:00 -0800 (PST) Received: by mail-pf1-f172.google.com with SMTP id 124so10724853pfy.0 for ; Wed, 28 Dec 2022 05:16:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=NqFWZj0OrWX/NfWGVhOwXpXBIdQ48KazDH2kS4ERCv0=; b=UFSHlToDl6C92M3e9cX1OXdLv0U+d0LPUsbEsPbCGiJN5rk2LDvWoM75giDsx3tTbu bladtX0LzdqmYAqOFzcYRLIcIanwxMR+a+i55MRjU+nBxEWNS2JwgoAAmQNtlXp2PYez SsC8uGOosETTuOiFoSiufMh31//SnBoL+iv5baOlJd7DzPTK7czR9YieXxhtk9ZmqB5m ryFAOBzXMPtPPFqlQT1Yb2VOqrvGB7WU17nOyqHy7hgDwNV6fAxpJSX6K9jkbpls3+JL RnGX6DuOu52oK0+wuNYfmVhJ8wXDvIj2RgSgMVCO/Ai2dS5SchaHKvbTFaLvtdhoji5N rBcw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=NqFWZj0OrWX/NfWGVhOwXpXBIdQ48KazDH2kS4ERCv0=; b=HM10A8S+7LxkMXdHx88r3XFz19Y86ChkvB0SILiHt4XwgGef0OVJpdmStSb6oWLIH8 EWIvjGOliyHVy7TS3D5ycmGAgqTkYtOgxaEfcD5j50NyvK1QZy+Ns0JpMSk7XktvMpSa I6TGscG+BUd61POvUGASkNdmAmxDk+A/kNkLD9updF01Xpw+RFjkw5MeJIbUyY7CkdMZ TJkXoZ44gCbKqAQpRJNmktMsVQhRMXT5bUS2qjuVuD2+3bYIXgtEbWLyE48xKyb9CYHM ryQjAwzol7DE1RrNm4xU2fv/rJ2FivNvdnor9ZyBElS++xorjoScf5UwPbbgawqUk7mp 1AQw== X-Gm-Message-State: AFqh2koZbxvDfY8b2E7py7NgJzD1nqvyo6MO4lEatVuMic5MawfVPk3C kTKS3ZIsmMo24J33wlsivvkNsVPKPvq/cevCTwD2N3hhm8c= X-Google-Smtp-Source: AMrXdXs4iNtutg2U/mQ//gQGqHcq3Ehc65Nv9OyBW8MJfLmu32Sj7F6c40uYWKT3MMYphD+C62PdnBernMPQKT1zW3g= X-Received: by 2002:a63:fe06:0:b0:492:23d5:1e3a with SMTP id p6-20020a63fe06000000b0049223d51e3amr1397183pgh.386.1672233359555; Wed, 28 Dec 2022 05:15:59 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: Date: Wed, 28 Dec 2022 13:15:47 +0000 Message-ID: To: =?UTF-8?B?UmFmYWVsIEZlcm7DoW5kZXogTMOzcGV6?= Cc: "internals@lists.php.net" , Asen Alexandrov Content-Type: multipart/alternative; boundary="00000000000060c04905f0e32bac" Subject: Re: [PHP-DEV] PHP build for the wasm32-wasi target From: george.banyard@gmail.com ("G. P. B.") --00000000000060c04905f0e32bac Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Thu, 22 Dec 2022 at 16:04, Rafael Fern=C3=A1ndez L=C3=B3pez wrote: > 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 th= e > wasm32-wasi target. WASI [1] is a system interface that allows WebAssembl= y > 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 tha= t > 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 nex= t > 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=3DUTF-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 bel= ow > 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 feature= s > PHP 7.4.32 and explains a bit of the context of this work. > > > Thank you, > Rafael Fern=C3=A1ndez L=C3=B3pez. > > [1] https://wasi.dev/ > [2] > https://github.com/bytecodealliance/wasmtime/blob/03463458e426d4bd0601ebd= 82e95b668fc982443/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/ph= p/php-7.3.33/patches > [9] > https://github.com/vmware-labs/webassembly-language-runtimes/blob/main/ph= p/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/ph= p/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=3DjXe8kulUscQ > [15] https://youtu.be/yo30oF1Gflo?t=3D7361 Hello Rafael, While this is impressive, this looks very similar to https://github.com/seanmorris/php-wasm in that it compiles the whole interpreter to WASM. Something I personally find of rather limited utility, even more so when in this iteration when the current interpreter already works server side. Mainly because I don't really see what benefits this gives to the language. Wouldn't this be just slower than executing the interpreter currently? I spent some time a couple of months ago thinking about trying to actually compile PHP code to WASM directly *without* compiling the whole interpreter, be that either by only compiling the existing opcodes to WASM or compiling directly from PHP to WASM. Now, this is clearly several magnitudes harder as a problem to solved, but is one that seems to have more benefits than just compiling the interpreter. Having a lot of the standard library, actually written in PHP, would be a big benefit here. And would make this project similar to RPython (what PyPy uses to compile its Python subset into C). The other issue is that I don't know of a way to run WASM binaries from PHP at the moment, from a quick search and from what I remembered Tuleap [1] achieved this by executing the WASM via Rust and using FFI to call the Rust function from PHP, which looks extremely clunky and something that maybe should be improved as an orthogonal project. Best regards. George P. Banyard [1] https://blog.tuleap.org/untrusted-code-execution-in-php-with-ffi-and-webass= embly --00000000000060c04905f0e32bac--