Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:125613 X-Original-To: internals@lists.php.net Delivered-To: internals@lists.php.net Received: from php-smtp4.php.net (php-smtp4.php.net [45.112.84.5]) by qa.php.net (Postfix) with ESMTPS id 645B11A00BD for ; Wed, 18 Sep 2024 02:30:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1726626743; bh=bxEVkygLFIyL6/Nzy2/1hSBV3EcPxy2B3F9w9gaVWF0=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=XYSar/hL6wrpQ+J3pAufokRVNYfNWpWRooy81XvvTqdecwO/UQ47boF0KZxhQDjlM DdNtOO7hktGzrDJgjrbsXby5a1v4t1q1sRs6MMlwFJHmUlQ9lx6D/Lf++lnHxcT7rD tJpvQAjEAAcs5ikJGceqJdfQyvY5AlF/iWFIl82D0e3OeR5ncdM1T0zzvf+CyK6D+5 6omuYdXCYA5B32RpSvPLl1gogE3ZaM/pM/Hzg1BYBuleNF5ChxaBaFcGpZ5UTy3cop FAj5FQtHON34ceTmQBK8lQBLcxnud0b09pyuSzDUIuhpehcqHXr2VBA+q0vi0mV8JF cyb9sXmrswCVw== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 9CBD0180061 for ; Wed, 18 Sep 2024 02:32:22 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=0.6 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,HTML_MESSAGE, SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from mx1.dfw.automattic.com (mx1.dfw.automattic.com [192.0.84.151]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Wed, 18 Sep 2024 02:32:22 +0000 (UTC) Received: from localhost (localhost.localdomain [127.0.0.1]) by mx1.dfw.automattic.com (Postfix) with ESMTP id 411E5340BF3 for ; Wed, 18 Sep 2024 02:30:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=automattic.com; h=content-type:content-type:x-mailer:mime-version:references :in-reply-to:message-id:subject:subject:from:from:date:date :received:received:received:received:received:received; s= automattic1; t=1726626615; bh=bxEVkygLFIyL6/Nzy2/1hSBV3EcPxy2B3F 9w9gaVWF0=; b=cpwVcjX0PXmS2jCdLExK2JUqrwZC26EzdsBuIWgh9GgIWis2yZ BLqtHxaDkWgp9b4q4g/kwQWgNNX6u9vaZCMPxFT2ZVYNw0ECDmjdg7MAre7K5Qf6 kXsmzxti0FYN6adaAwyzbMa96IOiAOho8oDVjtXVjbC5PIISmt2NNWlN3vxukNhe OwG8du3Us/pU4JJUu2hXBF/2nX/lW08lEG/O47awvcaAskQpCwnKrJ/cuG2Hfsjx weZRs41LFVFadt18+37xQQd6uB3yiZA7VspXWfoOxhqPc5RX5a42Or3oAyYkgAQA XtI2ZPsJkCRoC3+nbrPyOM4VLp41jZMfdF9Q== X-Virus-Scanned: Debian amavisd-new at wordpress.com Received: from mx1.dfw.automattic.com ([127.0.0.1]) by localhost (mx1.dfw.automattic.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id DmBtu7AQ-ans for ; Wed, 18 Sep 2024 02:30:15 +0000 (UTC) Received: from smtp-gw.dca.automattic.com (smtp-gw.dca.automattic.com [192.0.97.210]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx1.dfw.automattic.com (Postfix) with ESMTPS id 97442340CCF for ; Wed, 18 Sep 2024 02:30:15 +0000 (UTC) Authentication-Results: mail.automattic.com; dkim=pass (2048-bit key; unprotected) header.d=automattic.com header.i=@automattic.com header.b="N2noOL0K"; dkim=pass (2048-bit key; unprotected) header.d=automattic.com header.i=@automattic.com header.b="h9hrdHGp"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=automattic.com header.i=@automattic.com header.b="BU14c3aJ"; dkim-atps=neutral Received: from smtp-gw.dca.automattic.com (localhost.localdomain [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-gw.dca.automattic.com (Postfix) with ESMTPS id 3A9E5A09E1 for ; Wed, 18 Sep 2024 02:30:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=automattic.com; s=automattic2; t=1726626615; bh=bxEVkygLFIyL6/Nzy2/1hSBV3EcPxy2B3F9w9gaVWF0=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=N2noOL0KcEVmggpp+Mfptax0YemP+oQX65hUPKOqGOA3zpaVa5UwMhPirHD2y3njU ZIEaeL75enmkIGAjIMfclUXFDE14rw54iafscW5jT0AR/XMTYWLM33/sfjank//aS2 +1BuR9raSptAM9ZsHHhxQJp0DKOMo5u8FMntfkx1QRTR2CmTpanNsaGV75dBw2j7Wx OQYgHDWmS+z+IFUYIRo40R0BfrTMWD5BtzTTnvRTOrVl/kSLjglMLHBbsr3E5H8y04 MI/mh1YlkLlR3tnNdI6IJBFS9Ze8uXpHePJEb+aWy8n02RzpoKQ7Xf2bDujnbWzv9X L9JV+AFPRCT2Q== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=automattic.com; s=automattic1; t=1726626615; bh=bxEVkygLFIyL6/Nzy2/1hSBV3EcPxy2B3F9w9gaVWF0=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=h9hrdHGpgMPPdkoGnb152EoZtsa+6CoQxS4MM9Nhie7o3EPPauNpqz9K6H8+WA4gh qKEmuUp4MK36mSxJs95yMtW9tL4Xro5ibF3nNPdzRjtuhOJJzi1dMUhORL+nL6K3nz j1Wrb1zuMY3SbcoPBGLOyLS09CcvSrEFkjfkmaVZFCPPKGhRnjfhlor8/rR7kEhEu6 q5GiIYCNYUt9s/TFDT5Vbv7P3YMSEwfMifFH3wBsf49KvyPcGugLS9ZCqOebUcXEV4 0J6vFVee1ZKoC99OTUR5AUQ8WQ2PWhiuohi+ej+reFnixGLsi6FXX9uGSsfJy5xi4C FVkZuFz5qYE9Q== Received: from mail-pj1-f70.google.com (mail-pj1-f70.google.com [209.85.216.70]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-gw.dca.automattic.com (Postfix) with ESMTPS id 12799A09B9 for ; Wed, 18 Sep 2024 02:30:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=automattic.com; s=automattic2; t=1726626615; bh=bxEVkygLFIyL6/Nzy2/1hSBV3EcPxy2B3F9w9gaVWF0=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=BU14c3aJ0oHREYbf0K+GZQ1OoKCrpEkRdbgmRn5ltltzHUbE0oDnXFkNrSo5QpxXJ L2HX+SpTnYIlnYuPnXCUYroOFUxYxbbULhn7SOrU7pZD6Js8QyUzGrHywaI0q47tC3 Qu09C+lDCrbM+2S3LAXodJgbgIOVTF0RBanV6w+eh/gn5hyKWefel/X24ihZV0ywLm JeUsbE/mhqZQYI7UBrIGhYSKOsmlSKh0zPJUsRSibGKlVJFmdLofHjdxplfGVV5B+/ ++rU6f99UNz45nZpTFfTmc2m+TnBfhcK3wisMAzkEXIFAyyysuOEgxQpzwxnIpEoQc KjAF4enwSwC9g== Received: by mail-pj1-f70.google.com with SMTP id 98e67ed59e1d1-2d9a2b8af50so6298862a91.0 for ; Tue, 17 Sep 2024 19:30:15 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726626614; x=1727231414; h=mime-version:references:in-reply-to:message-id:subject:cc:to:from :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=kS6pwYg0DfAwAvB4Y7c23rCP0GZNvzw2IX6lkkxxx60=; b=kBeHBmpB7dg/eluH1qXIWMs7yZHKpTxhWTGigBu00+LRPdJ5/WN2DjA//g+ygp1ivO V2tUcIxqd2+LEsP8nYpNEpAKOlJ5o26651tmAxjnSuSAWOZ1YVt/Fc3BvAQFWEfYekbc Z7U+DsrdbcMpNEhALJrEgC5jx5J5hQ7wbSFFi4fPZc0RdJt9lthGXOwX9S9B7IqHYTMV HbiAChkN5fq7zTEuYRCs6sJ7MgiSwCnnBY2CSMNmDZ34gbFvYSk03zuCGx4TeUN0WJKj mgX42N+su8dKvU2Fz6cEU7JKAFZfMrILXOAHBjF3mnIkLYR7ysOzqANSHZYqBk2+hUzv DiHQ== X-Forwarded-Encrypted: i=1; AJvYcCVrLLd1sJgplfmentzmp39A/v79Az+lLRx1lvjDGwO1eNMcI5z9ATALrqNKMT7pG9z6jLJouZxQjJw=@lists.php.net X-Gm-Message-State: AOJu0YyZmJ0SaVQIB3Y5mSDQIZiOTHX4WhqVvmT2pzkpGfCV/FaVKhui 0n8N21cvBBI+RZW+EO0b2Tv3yYlMdULu0gYWvWNZ4Z1M15XBuzBUfbiynICK5IVQS22HjrWDLbP 1x6KD3Oa78Ba5wX2lEweabKfP2FB6DAXv0N5cbh1WJEJdCpBmc9qphKQ= X-Received: by 2002:a17:90b:3ec1:b0:2d8:ebef:547 with SMTP id 98e67ed59e1d1-2dbb9f08b33mr20671189a91.35.1726626614181; Tue, 17 Sep 2024 19:30:14 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEcuiv+fjGMap6YOEiWAelFPLIi3gx3zhVZqZ/7dEs6cmpOvhXPNadCc7tBNIzVS2GrOelRaQ== X-Received: by 2002:a17:90b:3ec1:b0:2d8:ebef:547 with SMTP id 98e67ed59e1d1-2dbb9f08b33mr20671139a91.35.1726626613259; Tue, 17 Sep 2024 19:30:13 -0700 (PDT) Received: from [192.168.22.187] ([204.98.75.5]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2dd6082e337sm238901a91.8.2024.09.17.19.30.12 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 17 Sep 2024 19:30:12 -0700 (PDT) Date: Tue, 17 Sep 2024 19:30:12 -0700 (PDT) X-Google-Original-Date: 17 Sep 2024 19:30:07 -0700 X-Google-Original-From: Dennis Snell To: Rob Landers Cc: Adam Zielinski , Mike Schinkel , Hammed Ajao , PHP internals Subject: Re: [PHP-DEV] Zephir, and other tangents Message-ID: In-Reply-To: References: <8D420123-4ECF-48FD-A9C3-F80C60457A37@newclarity.net> Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 X-Mailer: Unibox (443:23.6.0) Content-Type: multipart/alternative; boundary="=_988767A7-3C8A-481A-8EA4-826A0A89F180" From: dennis.snell@automattic.com (Dennis Snell) --=_988767A7-3C8A-481A-8EA4-826A0A89F180 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable > On Sep 17, 2024, at 2:03 PM, Rob Landers wrote: >=20 >=20 >=20 >=20 >=20 > On Tue, Sep 17, 2024, at 14:57, Adam Zielinski wrote: >=20 >>> To summarize, I think PHP would benefit from: >>=20 >>> >>=20 >>> 1. Adding WASM for simple low-level extensibility that could run on >>=20 >>> shared hosts for things that are just not possible in PHP as described a >>=20 >>> few paragraphs prior, and where we could enhance functionality over tim= e, >>=20 >>> >>=20 >>> 2. Constantly improving PHP the language, which is what you are solely >>=20 >>> advocating for over extensibility, >>=20 >> Hi Mike, >>=20 >>=20 >>=20 >> I=E2=80=99m Adam, I'm building WordPress Playground [1] =E2=80=93 it's W= ordPress running in the browser via a WebAssembly PHP build [2]. I'm excite= d to see this discussion and wanted to offer my perspective. >>=20 >>=20 >>=20 >> WebAssembly support in PHP core would be a huge security and productivit= y improvement for the PHP and WordPress communities. >>=20 >>=20 >>=20 >>> To summarize, I think PHP would benefit from: >>=20 >>> >>=20 >>> 1. Adding WASM for simple low-level extensibility that could run on >>=20 >>> shared hosts for things that are just not possible in PHP as described a >>=20 >>> few paragraphs prior, and where we could enhance functionality over tim= e, >>=20 >>=20 >>=20 >> Exactly this! With WASM, WordPress would get access to fast, safe, and b= attle-tested libraries. >>=20 >>=20 >>=20 >> Today, we're recreating a lot of existing libraries just to be able to u= se them in PHP, e.g. parsers for HTML [3], XML [4], Zip [5], MySQL [6], or = an HTTP client [7]. There are just no viable alternatives. Viable, as in wo= rking on all webhosts, having stellar compliance with each format's specifi= cation, supporting stream parsing, and having low footprint. For example, t= he curl PHP extensions is brilliant, but it's unavailable on many webhosts. >>=20 >>=20 >>=20 >> With WebAssembly support, we could stop rewriting and start leaning on t= he popular C, Rust, etc. libraries instead. Who knows, maybe we could even = polyfill the missing PHP extensions? >>=20 >>=20 >>=20 >>> 2. Constantly improving PHP the language, which is what you are solely >>=20 >>> advocating for over extensibility, >>=20 >>=20 >>=20 >> Just to add to that =E2=80=93 I think WASM support is important for PHP = to stay relevant. There's an exponential advantage to building a library on= ce and reusing it across the language boundaries. A lot of companies is inv= ested in PHP and that won't change in a day. However, lacking access to the= WASM ecosystem, I can easily imagine the ecosystem slowly gravitating towa= rds JavaScript, Python, Go, Rust, and other WASM-enabled languages. >>=20 >>=20 >>=20 >> Security-wise, WebAssembly is Sandboxed and would enable safe processing= of untrusted files. Vulnerabilities like Zip slip [8] wouldn't affect a sa= ndboxed filesystem. Perhaps we could even create a secure enclave for runni= ng composer packages and WordPress plugins without having to fully trust th= em. >>=20 >>=20 >>=20 >> Another use-case is code reuse between JavaScript and PHP. I'm sceptical= this could work with reasonable speed and resource consumption, but let's = assume for a moment there is a ultra low overhead JavaScript runtime in Web= Assembly. WordPress could have a consistent templating language. PHP backen= d would render the website markup using the same templates and libraries as= the JavaScript frontend. Half the code would achieve the same task. >>=20 >>=20 >>=20 >> Also, here's a few interesting "WASM in PHP" projects I found =E2=80=93 = maybe they would be helpful: >>=20 >> - WebAssembly runtime built in PHP (!)=C2=A0https://github.com/jasperwey= ne/unwasm >>=20 >>=20 >> - WebAssembly runtime as a PHP language extension:=C2=A0https://github.c= om/veewee/ext-wasm >>=20 >>=20 >> - WebAssembly runtime as a PHP language extension:=C2=A0https://github.c= om/extism/php-sdk >>=20 >>=20 >>=20 >>=20 >> [1]=C2=A0https://github.com/WordPress/wordpress-playground/ >>=20 >>=20 >> [2]=C2=A0https://github.com/WordPress/wordpress-playground/tree/trunk/pa= ckages/php-wasm/compile >>=20 >>=20 >> [3]=C2=A0https://developer.wordpress.org/reference/classes/wp_html_proce= ssor/ >>=20 >>=20 >> [4]=C2=A0https://github.com/WordPress/wordpress-develop/pull/6713 >>=20 >>=20 >> [5]=C2=A0https://github.com/WordPress/blueprints-library/blob/87afea1f9a= 244062a14aeff3949aae054bf74b70/src/WordPress/Zip/ZipStreamReader.php >>=20 >>=20 >> [6]=C2=A0https://github.com/WordPress/sqlite-database-integration/pull/1= 57 >>=20 >>=20 >> [7]=C2=A0https://github.com/WordPress/blueprints-library/blob/trunk/src/= WordPress/AsyncHttp/Client.php >>=20 >>=20 >> [8]=C2=A0https://security.snyk.io/research/zip-slip-vulnerability >>=20 >>=20 >>=20 >>=20 >> -Adam >>=20 >>=20 >>=20 >>=20 >>=20 >>=20 >>=20 >=20 > Hey Adam, >=20 >=20 >=20 > I actually went down something like this road for a bit when working at A= utomattic. My repo even probably still exists in the graveyard repository= =E2=80=A6 but I had plugins running in C# and Java over a couple of weeks. = This was long before wasm was a thing, and while cool, nobody really could = think of a use for it. >=20 >=20 >=20 > It seems like you have a use for it though, and I=E2=80=99m reasonably ce= rtain you could get it working over ffi in a few weeks; yet you mention hos= ts not even having the curl extension installed, so I doubt that even if wa= sm came to be, it would be available on those hosts. >=20 >=20 There are two major areas I have found that would benefit from having a WAS= M runtime in PHP: Obviously, being able to run the same algorithms on the frontend and backen= d is a huge win for consistency in applications. Particularly with text-rel= ated algorithms it=E2=80=99s really easy for inconsistencies to develop due= to the features available in each languages standard library, as well as d= ue to differences in how each language handles and processes string. The other major area is similar, and we=E2=80=99ve seen this with the HTML = and XML parsing work recently undertaken in WordPress. There are plenty of = cases where efficient and spec-compliant operations are valuable, but these= kinds of things tend to cost significantly more in user-space PHP. Being a= ble to jump into WASM, even with the overhead of exchanging that data and r= unning another VM, would very likely result in a noticeable net improvement= in runtime performance. Additionally, it=E2=80=99s a perk being able to wr= ite such algorithms in languages that aid that development through more pow= erful type systems. There=E2=80=99s additional value in a number of other separate tasks. Conve= rting images or generating thumbnails is a good example where raw performan= ce is less of a concern than being able to ensure that the image library is= available and not exposing the host system to risk. I imagine plenty of = =E2=80=9CPHP lite-extensions=E2=80=9D appearing in this space because it wo= uld give people the opportunity to experiment with features that are imprac= tical in user-space PHP before fully committing the language itself to that= interface or library. It would extend the reach of PHP=E2=80=99s usability= because it would make possible for folks, who happen to be running on chea= p shared hosts, to run more complicated processing tasks than are practical= today. While big software shops and SaaS vendors do and can run their own = custom PHP extensions, there=E2=80=99s not great way to share those general= ly to people without the same full control over their stack. >=20 >=20 >=20 > However, plugins basically work via hooks/filters. So as long as you regi= ster the right listeners and handle serialization properly, you can simply = run a separate process for the plugin, or call a socket for =E2=80=9Cremote= =E2=80=9D plugins. >=20 >=20 >=20 > I don=E2=80=99t see anything stopping anyone from implementing that today. >=20 >=20 > =E2=80=94 Rob >=20 I=E2=80=99m excited to see this conversation. I=E2=80=99ve wanted to propos= e it a number of times myself. Warmly, Dennis Snell --=_988767A7-3C8A-481A-8EA4-826A0A89F180 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable

On Sep 17, 2024, at 2:03 PM, Rob Landers <rob@bottled.codes> wro= te:



On Tue, S= ep 17, 2024, at 14:57, Adam Zielinski wrote:
> To summarize, I think PHP would benefit from:
>
> 1. Adding WASM for simple low-level extensibility that could run = on
> shared hosts for things that are just not possible in PHP as desc= ribed a
> few paragraphs prior, and where we could enhance functionality ov= er time,
>
> 2. Constantly improving PHP the language, which is what you are s= olely
> advocating for over extensibility,
Hi Mike,

I=E2=80=99m Adam, I'm building WordPress Playground [1] =E2=80=93 it's= WordPress running in the browser via a WebAssembly PHP build [2]. I'm exci= ted to see this discussion and wanted to offer my perspective.

WebAssembly support in PHP core would be a huge security and productiv= ity improvement for the PHP and WordPress communities.

> To summarize, I think PHP would benefit from:
>
> 1. Adding WASM for simple low-level extensibility that could run = on
> shared hosts for things that are just not possible in PHP as desc= ribed a
> few paragraphs prior, and where we could enhance functionality ov= er time,

Exactly this! With WASM, WordPress would get access to fast, safe, and= battle-tested libraries.

Today, we're recreating a lot of existing libraries just to be able to= use them in PHP, e.g. parsers for HTML [3], XML [4], Zip [5], MySQL [6], o= r an HTTP client [7]. There are just no viable alternatives. Viable, as in = working on all webhosts, having stellar compliance with each format's speci= fication, supporting stream parsing, and having low footprint. For example,= the curl PHP extensions is brilliant, but it's unavailable on many webhost= s.

With WebAssembly support, we could stop rewriting and start leaning on= the popular C, Rust, etc. libraries instead. Who knows, maybe we could eve= n polyfill the missing PHP extensions?

> 2. Constantly improving PHP the language, which is what you are s= olely
> advocating for over extensibility,

Just to add to that =E2=80=93 I think WASM support is important for PH= P to stay relevant. There's an exponential advantage to building a library = once and reusing it across the language boundaries. A lot of companies is i= nvested in PHP and that won't change in a day. However, lacking access to t= he WASM ecosystem, I can easily imagine the ecosystem slowly gravitating to= wards JavaScript, Python, Go, Rust, and other WASM-enabled languages.

Security-wise, WebAssembly is Sandboxed and would enable safe processi= ng of untrusted files. Vulnerabilities like Zip slip [8] wouldn't affect a = sandboxed filesystem. Perhaps we could even create a secure enclave for run= ning composer packages and WordPress plugins without having to fully trust = them.

Another use-case is code reuse between JavaScript and PHP. I'm sceptic= al this could work with reasonable speed and resource consumption, but let'= s assume for a moment there is a ultra low overhead JavaScript runtime in W= ebAssembly. WordPress could have a consistent templating language. PHP back= end would render the website markup using the same templates and libraries = as the JavaScript frontend. Half the code would achieve the same task.

Also, here's a few interesting "WASM in PHP" projects I found = =E2=80=93 maybe they would be helpful:
- WebAssembly runtime built in PHP (!)=C2=A0https:= //github.com/jasperweyne/unwasm
- WebAssembly runtime as a PHP language extension:=C2=A0https://github.com/veewee/ext-wasm
- WebAssembly runtime as a PHP language extension:=C2=A0https://github.com/extism/php-sdk


-Adam



Hey Adam,=

I actuall= y went down something like this road for a bit when working at Automattic. = My repo even probably still exists in the graveyard repository=E2=80=A6 but= I had plugins running in C# and Java over a couple of weeks. This was long= before wasm was a thing, and while cool, nobody really could think of a us= e for it.

It seems = like you have a use for it though, and I=E2=80=99m reasonably certain you c= ould get it working over ffi in a few weeks; yet you mention hosts not even= having the curl extension installed, so I doubt that even if wasm came to = be, it would be available on those hosts.

There are two major areas I have found that would benefit from having = a WASM runtime in PHP:

Obviously, being able to run the same algorithms on the frontend and b= ackend is a huge win for consistency in applications. Particularly with tex= t-related algorithms it=E2=80=99s really easy for inconsistencies to develo= p due to the features available in each languages standard library, as well= as due to differences in how each language handles and processes string.

The other major area is similar, and we=E2=80=99ve seen this with the = HTML and XML parsing work recently undertaken in WordPress. There are plent= y of cases where efficient and spec-compliant operations are valuable, but = these kinds of things tend to cost significantly more in user-space PHP. Be= ing able to jump into WASM, even with the overhead of exchanging that data = and running another VM, would very likely result in a noticeable net improv= ement in runtime performance. Additionally, it=E2=80=99s a perk being able = to write such algorithms in languages that aid that development through mor= e powerful type systems.

There=E2=80=99s additional value in a number of other separate tasks. = Converting images or generating thumbnails is a good example where raw perf= ormance is less of a concern than being able to ensure that the image libra= ry is available and not exposing the host system to risk. I imagine plenty = of =E2=80=9CPHP lite-extensions=E2=80=9D appearing in this space because it= would give people the opportunity to experiment with features that are imp= ractical in user-space PHP before fully committing the language itself to t= hat interface or library. It would extend the reach of PHP=E2=80=99s usabil= ity because it would make possible for folks, who happen to be running on c= heap shared hosts, to run more complicated processing tasks than are practi= cal today. While big software shops and SaaS vendors do and can run their o= wn custom PHP extensions, there=E2=80=99s not great way to share those gene= rally to people without the same full control over their stack.


However, = plugins basically work via hooks/filters. So as long as you register the ri= ght listeners and handle serialization properly, you can simply run a separ= ate process for the plugin, or call a socket for =E2=80=9Cremote=E2=80=9D p= lugins.

I don= =E2=80=99t see anything stopping anyone from implementing that today.

=E2=80=94 Rob

I=E2=80=99m excited to see this conversation. I=E2=80=99ve wanted to p= ropose it a number of times myself.

Warmly,
Dennis Snell
--=_988767A7-3C8A-481A-8EA4-826A0A89F180--