Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:125636 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 6F09C1A00BD for <internals@lists.php.net>; Fri, 20 Sep 2024 06:15:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1726813042; bh=OXUuwkKDvpsZVz4SX5YPKvWXcWy6XMb5vYdcxFcj1ZA=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=OymUKLm5qzs+IPDdpxqoRCn8qG4v2mqgQkQ8vTZjiK/yB3vygFWbO1RM0OcLWu4Y4 sFr1UuWUZOyNqINyzkFWlaFf81ebB50kau7u9jW35NVZ8v551ppNUYc6GVCmawRHjG 5g/lPgZDOXG7GuycRJ0jd5P7VGjdWQU1mbZnkAeKehSwo2FI8l4A6FEW13EyIrYhdN nZzysxQuHcr1pNGVcd5eFYUvj897nJDd/KQWPa6hIjRCFGN7zfH9G+E5PMCRDeynVg FmOw6PEWagjK4fFaOJkKnCfhCJspfsLHAEuwCNg54tPIV5oBl0GyOt16id1nGCm+lf SCGbmCEWXbqig== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 3DECA180032 for <internals@lists.php.net>; Fri, 20 Sep 2024 06:17:21 +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: <dennis.snell@automattic.com> 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 <internals@lists.php.net>; Fri, 20 Sep 2024 06:17:20 +0000 (UTC) Received: from localhost (localhost.localdomain [127.0.0.1]) by mx1.dfw.automattic.com (Postfix) with ESMTP id C08091DED27 for <internals@lists.php.net>; Fri, 20 Sep 2024 06:15:13 +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=1726812912; bh=OXUuwkKDvpsZVz4SX5YPKvWXcWy6XMb5vY dcxFcj1ZA=; b=TKVVLVe2MHacV9WYa7Cd5BGYbfRRRZbJ3N0qK/79xdPnr93j0k xt7id4hDGtw4B3f/zfFpnvP3gT3uK8mMAaTLG3u6Ke75pFNzZLH2EUT8as0VVnoS qUmeZwRdAu9TyS1bUCM3ARVk4OTwtveKI2L9leGP/xPIiC4BolJFk6jQIj4OckGb vYW3NpzNS8ZRDMJTFqbVABtOFsQNdZftWtxRBUdSjhOwM5zzzcEN8pJ24I2m0Zq4 XpapnQCUKCNNZk1N9zaf3xIcyrF9D3Tcr57SUQetdllllc9DtyCxYcKsE/bUJ/G5 3CG+Br+p+vhJ1Mc2ttFl1n00EajuvIWWiS9A== 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 ShnwABvYt6rm for <internals@lists.php.net>; Fri, 20 Sep 2024 06:15:12 +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 AD088340F46 for <internals@lists.php.net>; Fri, 20 Sep 2024 06:15:12 +0000 (UTC) Authentication-Results: mail.automattic.com; dkim=pass (2048-bit key; unprotected) header.d=automattic.com header.i=@automattic.com header.b="KH1QdGEU"; dkim=pass (2048-bit key; unprotected) header.d=automattic.com header.i=@automattic.com header.b="gZuclnSB"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=automattic.com header.i=@automattic.com header.b="ObLvXXbA"; 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 444F4A09E0 for <internals@lists.php.net>; Fri, 20 Sep 2024 06:15:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=automattic.com; s=automattic2; t=1726812912; bh=OXUuwkKDvpsZVz4SX5YPKvWXcWy6XMb5vYdcxFcj1ZA=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=KH1QdGEUGV/S1KSU+jG7oM2Bb3yrMlCNu7gxne6z+qeg7ifMN45mYqx3XSYo5B0XQ nxrx5nWG2oEXHsizQi6SOCdXmJSCP8+UesYEqzxbg+xIqNUpLZKVNQ5+CikKYPm0v+ Glt3K3rYBJqFeFIqIJazCbsOPDP0hJxiGamh1i0uq1y1xym7WGfa5lLdZC84lrtlO9 G/Hh9+h78SPpnb+Cd34gOlmB17sCRZS+44x18sJM2FUP0mL/CTSiVMxJI4jMPLil6G hclMxDHiv9iqBS+bza/Lj5K9UpImGaBj1ENmBhuoYVsjslhflVV2ChcyoliTcKJIbm 8vVljXtNHohMw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=automattic.com; s=automattic1; t=1726812912; bh=OXUuwkKDvpsZVz4SX5YPKvWXcWy6XMb5vYdcxFcj1ZA=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=gZuclnSBIVh6fOhB3wenT/ZUNEwkjlR1yuRWpbBHCZ40gICA8e9zGE0EayLNiU0Pc z9HcMqSrRAlEWt0L4rrooejiO/FMqfOS8l3i88Sl7lIpsxSsogXZFGnKPcCV/2Xbhh CBH/Eem2K/ZyW3haUK/3oDUFcCaNH05H1rvH4Ni4Ci6ISULGLluHNhtA38T3+TKJHm sV/jwwGALJ9fNNGyfJ4QCvd0tzelYbyheq8pJiqGEtwjr5wb3zyPyZLhagTopmnUad Wpa3mRyjJkaIS4uZWOfKqtVjsABaykeB0pZJJyZQb5zm/D9W75g7cF4nocpvhXQ9m6 1JYoLdSouqyew== Received: from mail-ot1-f69.google.com (mail-ot1-f69.google.com [209.85.210.69]) (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 1D8B8A09B9 for <internals@lists.php.net>; Fri, 20 Sep 2024 06:15:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=automattic.com; s=automattic2; t=1726812912; bh=OXUuwkKDvpsZVz4SX5YPKvWXcWy6XMb5vYdcxFcj1ZA=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=ObLvXXbAvTVOz6/jxh58qzO5iyey2y54c3uJhgZJHvheZSw3lntcGBHdoG/8W5xpx rqp3RBX6VkrXABzqkAGtn6wfCv4V9S6rZXPxqllbsAR2uCnE66Z+vhIh/iBcSvMCjN HGGFvPs3m5cmti/6V/oOc9sYh9QXHRmjlrtlMYAWB9rsX7/jhT1lea2FbYtdw3SGuB yQ0e6gEknxnI2gpmxgjLCHo+7zSDdytuwQ0jW2IO0RcIQ3QIgGt5esgPSzzq9jBrJg 3N6mUWa6GN1IaWghIa6pHhgvpbPDsLImhkwqx42/eBW0dzatPaj/Kfbfzhk55ZR7h4 a27j+saVCf11A== Received: by mail-ot1-f69.google.com with SMTP id 46e09a7af769-710e6500299so1861083a34.2 for <internals@lists.php.net>; Thu, 19 Sep 2024 23:15:12 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726812911; x=1727417711; 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=KFT+pJgfliGdagBv3NSi3brympXvVUpfCv3q+HwKv0g=; b=Aidj1Xj1fBPl3wCIdaOmtsHS0t4WX4pQij/vIp3gu6KZl6ExUkglkHsBi+hGfkyesG +DeNnNJK3o0xZGfgn9vhpCnU59fMGXtnQEp5/wnPwCqpXCFcOYw9SbK3NMnxPtPfIhR1 fADV5zcRIBxWyXEkb114TUuItNi1nac9xi8JTu0wiab9bg9wW3YteRqmCpSVQ+pJa4rx QmVSBrGdYR+rVnFricvo8jTgevdr9TZtd9eBG6fmLv3JVTjcbbQ/i5+WcCNzMqZT/DGk O25yhKJMoBtZSYIJ+AR5sdtS681CRXd7BOl7EpAbCCQhGEBzObBeiyZig8/MqK5HbwtL 61Vg== X-Forwarded-Encrypted: i=1; AJvYcCUTLcD02T7mQ06rsO6nM+RnawowxhT3S/ztB+UVWycnnf8n+eq2gzk4zkOL7cnEVijZT/trDwDYVB8=@lists.php.net X-Gm-Message-State: AOJu0YwZikguCtcJRbtgLaFKuppPycCOwhk3W7db3H2ZgvD7J3S5QdpZ /K+hwqyS7Vuwqj58t1m3tbK+hV+6378Z/q9ljodoW+f1sArgEpbC40sWihy4ab3F9sAJTkTM/YJ VthXOEgMlXscfRI/PrK/p3Bx/A94vTXkrQeL2ecMI70v7n/79i3zkGNs= X-Received: by 2002:a05:6830:258a:b0:70f:3720:16bb with SMTP id 46e09a7af769-713923e1cd4mr2057607a34.19.1726812911350; Thu, 19 Sep 2024 23:15:11 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHbNyAMr1513UbBv3LUgtSBg4WzH50PB0Fc2d2RV3Ex1Xu+xtBF5jComBLS8HWSbP0eZ8jyEA== X-Received: by 2002:a05:6830:258a:b0:70f:3720:16bb with SMTP id 46e09a7af769-713923e1cd4mr2057584a34.19.1726812910847; Thu, 19 Sep 2024 23:15:10 -0700 (PDT) Received: from [192.168.19.190] ([204.98.75.5]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-7db498e061dsm8649952a12.14.2024.09.19.23.15.10 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 19 Sep 2024 23:15:10 -0700 (PDT) Date: Thu, 19 Sep 2024 23:15:10 -0700 (PDT) X-Google-Original-Date: 19 Sep 2024 23:15:09 -0700 X-Google-Original-From: Dennis Snell <dennis.snell@automattic.com> To: Hammed Ajao <hamiegold@gmail.com> Cc: Rob Landers <rob@bottled.codes>, Adam Zielinski <adam.zielinski@automattic.com>, Mike Schinkel <mike@newclarity.net>, PHP internals <internals@lists.php.net> Subject: Re: [PHP-DEV] Zephir, and other tangents Message-ID: <7EA884D2-0F37-4BF1-AC97-DB6953C944E6@automattic.com> In-Reply-To: <CA+Jpajnk9i=EhqXaKnYUTHhA_1TfzB1qiLfRh1whPoO8Y8ECqA@mail.gmail.com> References: <A247BB36-9FD1-4AAF-AAB8-82DBD9DE3550@newclarity.net> <CA697780-BC2D-4054-A9FD-523E08236732@rwec.co.uk> <8D420123-4ECF-48FD-A9C3-F80C60457A37@newclarity.net> <CA+Jpajkx0OraH7GQyB5gECtPOo2JP=RzuSwqfv4AZGY+a+ryPw@mail.gmail.com> <AACF228F-53D3-480F-9127-77FBC4AE6A84@newclarity.net> <CAGnYymDhy1dov+4HcFWhAx1Ga9bXR=Urew9RbN5KEXcgHmk=Ew@mail.gmail.com> <f433fbe1-bee4-4a61-ba18-90053975b29e@app.fastmail.com> <BB0310CD-8134-4B3F-9C51-B59B5A24405F@automattic.com> <CA+Jpajnk9i=EhqXaKnYUTHhA_1TfzB1qiLfRh1whPoO8Y8ECqA@mail.gmail.com> Precedence: bulk list-help: <mailto:internals+help@lists.php.net list-unsubscribe: <mailto:internals+unsubscribe@lists.php.net> list-post: <mailto:internals@lists.php.net> 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="=_636E1804-EA8C-44B6-A10E-3277151D3099" From: dennis.snell@automattic.com (Dennis Snell) --=_636E1804-EA8C-44B6-A10E-3277151D3099 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Hi Hammed, thank you for taking the time to read through this and share you= r thoughts. > On Sep 19, 2024, at 1:41 PM, Hammed Ajao <hamiegold@gmail.com> wrote: >=20 >=20 >=20 >=20 > On Tue, Sep 17, 2024 at 8:30=E2=80=AFPM Dennis Snell <dennis.snell@automa= ttic.com >> wrote: >=20 >>=20 >>=20 >>=20 >>> On Sep 17, 2024, at 2:03 PM, Rob Landers <rob@bottled.codes> 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 describe= d a >>>>=20 >>>>> few paragraphs prior, and where we could enhance functionality over t= ime, >>>>=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= 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. >>>>=20 >>>>=20 >>>>=20 >>>> WebAssembly support in PHP core would be a huge security and productiv= ity 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 describe= d a >>>>=20 >>>>> few paragraphs prior, and where we could enhance functionality over t= ime, >>>>=20 >>>>=20 >>>>=20 >>>> Exactly this! With WASM, WordPress would get access to fast, safe, and= battle-tested libraries. >>>>=20 >>>>=20 >>>>=20 >>>> 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. >>>>=20 >>>>=20 >>>>=20 >>>> 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? >>>>=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 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. >>>>=20 >>>>=20 >>>>=20 >>>> 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. >>>>=20 >>>>=20 >>>>=20 >>>> 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. >>>>=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/jasperw= eyne/unwasm >>>>=20 >>>>=20 >>>> - WebAssembly runtime as a PHP language extension:=C2=A0https://github= .com/veewee/ext-wasm >>>>=20 >>>>=20 >>>> - WebAssembly runtime as a PHP language extension:=C2=A0https://github= .com/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/= packages/php-wasm/compile >>>>=20 >>>>=20 >>>> [3]=C2=A0https://developer.wordpress.org/reference/classes/wp_html_pro= cessor/ >>>>=20 >>>>=20 >>>> [4]=C2=A0https://github.com/WordPress/wordpress-develop/pull/6713 >>>>=20 >>>>=20 >>>> [5]=C2=A0https://github.com/WordPress/blueprints-library/blob/87afea1f= 9a244062a14aeff3949aae054bf74b70/src/WordPress/Zip/ZipStreamReader.php >>>>=20 >>>>=20 >>>> [6]=C2=A0https://github.com/WordPress/sqlite-database-integration/pull= /157 >>>>=20 >>>>=20 >>>> [7]=C2=A0https://github.com/WordPress/blueprints-library/blob/trunk/sr= c/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= 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 use for it. >>>=20 >>>=20 >>>=20 >>> It seems like you have a use for it though, and I=E2=80=99m reasonably = certain you could get it working over ffi in a few weeks; yet you mention h= osts not even having the curl extension installed, so I doubt that even if = wasm came to be, it would be available on those hosts. >>>=20 >>>=20 >>=20 >> There are two major areas I have found that would benefit from having a = WASM runtime in PHP: >>=20 >>=20 >> Obviously, being able to run the same algorithms on the frontend and bac= kend is a huge win for consistency in applications.=C2=A0 >>=20 >>=20 >>=20 >=20 > I'm not convinced. That's what they said about nodejs(same algos and same= language on FE and BE). Except it's not really that consistent because the= re are several discrepancies between the browser and node runtime. I'll bel= ieve it when I see it. >=20 >=20 >=20 There=E2=80=99s a note about this point that I think is worth calling out, = and that is something you probably already know, but JavaScript runtimes pr= ovide a standard library while a WASM runtime is mostly just a virtual mach= ine. There=E2=80=99s also nothing provided that I=E2=80=99m aware of in WAS= M that offers filesystem access or network access, which are major areas wh= ere in-browser JavaScript and NodeJS backends differ (because the browser a= nd server environments are fundamentally limited by different needs). As things stand, projects are compiled into WebAssembly and literally run i= dentically in the different runtimes because it=E2=80=99s the bytecode that= =E2=80=99s specified, not specific functions or libraries. Whereas with Jav= aScript we=E2=80=99re shipping source code and interacting with very differ= ent systems, WASM bundles are a few steps removed from that, and have no DO= M or system access to interact with. I=E2=80=99m fairly confident we can say that it=E2=80=99s non-controversial= that folks routinely run identical algorithms across different WASM runtim= es in different environments. As you mentioned elsewhere, it=E2=80=99s very= much akin to how Java and Closure and Scala all run on the JVM just fine t= ogether even being different languages, except in this case the runtime is = an isolated sandbox by default with no external system access. WASM is a lo= vely little VM, successful in ways many before it haven=E2=80=99t been. > =C2=A0 >> Particularly with text-related algorithms it=E2=80=99s really easy for i= nconsistencies to develop due to the features available in each languages s= tandard library, as well as due to differences in how each language handles= and processes string. >>=20 >>=20 >>=20 >=20 > I can see the appeal of that though. >=20 >=20 >>=20 >>=20 >> The other major area is similar, and we=E2=80=99ve seen this with the HT= ML and XML parsing work recently undertaken in WordPress. >>=20 >>=20 >>=20 >=20 >=20 >=20 > Yeah you could talk about html parsing before 8.4 but with 8.4 we get lex= bor (thanks to niels) and that's as good as it gets. Php already has beauti= ful support for XML though so I'm not sure why you would implement a parser= yourself. >=20 It=E2=80=99s wonderful that PHP is finally getting a spec-compliant HTML DO= M parser for the first time in its history, but \Dom\HTMLDocument is not th= e right interface for every server need, and remains ill-suited for the kin= d of work typical in a WordPress site, which needs to run on low memory bud= gets, perform as fast as possible, and exceed the safety of what a generic = DOM parser produces (there are cases that \Dom\HTMLDocument will still intr= oduce vulnerabilities into an HTML document because it=E2=80=99s able to cr= eate DOM trees that cannot be represented by HTML upon serialization, and a= s it implements the HTML spec, it cannot prevent creating those trees). The= re are still a number of steps every developer needs to take to properly se= tup the parser and get the right results back, and the parser has to load t= he entire DOM tree into memory before any reads or manipulations can be per= formed on it. WordPress=E2=80=99 HTML API is a near-zero memory overhead streaming HTML p= arser designed around safe-by-default reading and writing of HTML which req= uires no configuration or manual steps to get =E2=80=9Cthe right thing.= =E2=80=9D It=E2=80=99s also significantly slower in user-space PHP than it = needs to be. I hope one day that PHP has its own copy of this streaming par= ser design, which is performant and available in every copy of PHP (which i= s another issue with code only available in extensions), but even if that n= ever happens, running C or Rust code compiled to WebAssembly would provide = almost the same value as having that design implemented in the language. >=20 >=20 >=20 >> 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. >>=20 >>=20 >>=20 >=20 >> Being 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 i= mprovement in runtime performance. >>=20 >>=20 >>=20 >=20 >=20 >=20 > What exactly do you mean by jump into wasm? Like hand write it? Or you me= an jump into a language that can be compiled to wasm? How about debugging a= t runtime? And if you mean better performance than PHP, while that is likel= y, it isn't guaranteed. PHP is pretty fast and will be faster for some rout= ines that are optimized by the engine. Wasm will never be as fast as extens= ions though because with extensions, all you're doing is extending the engi= ne. Same as any internal extension. With wasm you're interoperating with an= entirely separate VM. >=20 By jumping into WASM I=E2=80=99m talking about the second thing you mention= : calling functions written in languages compiled to WebAssembly. Even with= the overhead of marshaling data, the things that WebAssembly is good at ar= e the things that PHP is slow at: specifically things like raw numeric comp= utation and string manipulation and parsing. I write a lot of parsing code = and frequently am surprised at the overhead cost of string processing and a= rray operations in PHP. There are a number of straightforward operations av= ailable in C that just can=E2=80=99t be done in PHP. I don=E2=80=99t see th= is as a failing of PHP, just an aspect of how it is. For runtime debugging I don=E2=80=99t have any particular thoughts. I= =E2=80=99m not aware of anyone who has ever tried to runtime debug CURL cal= ls or things like `mb_convert_encoding()`. Functions invoked in the WASM ru= ntime would more or less be library functions, like `ffmpeg`. Debugging wou= ld likely most frequently be done as a library and dumped into the PHP appl= ication with no expectation for debugging. Effectively these are user-space PHP extensions, and are very convenient be= cause they can be updated without recompiling PHP or begging web hosts to u= pdate their PHP version, or to do that every other Tuesday, or whenever ano= ther security exploit is fixed in some image processor. On that note, the a= bility to sandbox image processing code (and any other user-provided conten= t) is a huge perk. Many of the exploits of past PHP extensions could be con= tained inside the VM, which has limited ability to reach out into the syste= m. Fixing vulnerabilities and bugs becomes something any auto-updater can a= ccomplish, requiring no effort or interaction on the part of the host. >=20 >=20 >> Additionally, it=E2=80=99s a perk being able to write such algorithms in= languages that aid that development through more powerful type systems. >>=20 >=20 >=20 >=20 > We can agree on that. But I use C++ for my extensions so there's also tha= t. >=20 >=20 >> There=E2=80=99s additional value in a number of other separate tasks. Co= nverting images or generating thumbnails is a good example where raw perfor= mance is less of a concern than being able to ensure that the image library= is available and not exposing the host system to risk.=C2=A0 >>=20 >=20 >=20 >=20 > Imo this is where FFI should shine but I'll admit that the current implem= entation is lacking in both security and functionality. >=20 >=20 >=20 >=20 >> I imagine plenty of =E2=80=9CPHP lite-extensions=E2=80=9D appearing in t= his space because it would give people the opportunity to experiment with f= eatures that are impractical 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 happe= n to be running on cheap shared hosts, to run more complicated processing t= asks 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 generally to people without the same full control over thei= r stack. >>=20 >=20 >=20 >=20 > Shared hosting for php gets you the worst possible version of php.=20 >=20 Couldn=E2=80=99t have said it better myself! > Can't recompile to enable any bundled extension, can't install any new ex= tensions, so how exactly would you approach this? Wasm bundled with the eng= ine by default? Or some kind of opt in mechanism that shared hosters won't = even be able to use? >=20 As with many of the things I=E2=80=99ve been writing on this list lately, t= o me, an embedded WASM runtime makes most sense as a central language featu= re and available everywhere PHP is deployed. There are a few core basic sub= systems that either are foundational to the environment PHP operates in (fo= r example, web-related technologies like HTTP and HTML and URLs) or which b= ring so much value to the language that it opens up brand new paradigms or = potentially removes major maintenance burdens. If we could ship `imagemagick` as a WASM extension there would be no need f= or the `imagemagick` extension. The security environment out of the box is = so much better; it=E2=80=99s not worth the lost potential for performance t= hat a native extension offers. Someone may not agree with this, and that= =E2=80=99s fine because they can always install a native extension or utili= ze the FFI on infrastructure they control. I think at times WordPress sees a very different picture of the world than = many great PHP projects see. Our reality is that we=E2=80=99re writing code= that runs on hardware we don=E2=80=99t control or even know about. We cann= ot in any way install or force certain extensions to be present. The worst = possible version of PHP is literally the constraint at which we are allowed= to code. Anything beyond that and we can=E2=80=99t ship it because a large= fraction of the internet will start crashing. It=E2=80=99s frustrating, bu= t also an honor to be able to ensure that people who can=E2=80=99t afford h= igh end servers can still build their own place on the world wide web. Over the past several years, though, WordPress has also been a positive inf= luence on persuading hosts to update their PHP versions, because PHP has go= tten better enough that the argument is easy: upgrade to PHP 7 and your dat= a center costs will drop X%. It=E2=80=99s not too hard to imagine winning s= imilarly on the security argument. WASM code on memory-constrained, oversubscribed, CPU-poor hosts is still co= nsiderably better for certain kinds of computation than user-space PHP code= on memory-constrained, oversubscribed, CPU-poor hosts. >=20 >=20 > >>=20 >>=20 >>>=20 >>>=20 >>>=20 >>> However, plugins basically work via hooks/filters. So as long as you re= gister the right listeners and handle serialization properly, you can simpl= y run a separate process for the plugin, or call a socket for =E2=80=9Cremo= te=E2=80=9D plugins. >>>=20 >>>=20 >>>=20 >>> I don=E2=80=99t see anything stopping anyone from implementing that tod= ay. >>>=20 >>>=20 >>> =E2=80=94 Rob >>>=20 >>=20 >> I=E2=80=99m excited to see this conversation. I=E2=80=99ve wanted to pro= pose it a number of times myself. >>=20 >>=20 >> Warmly, >> Dennis Snell=C2=A0 >>=20 >=20 > I actually love wasm, I'm currently in the process of compiling my mini p= hp runtime to wasm (basically a browser only version of 3v4l). I'm not agai= nst this for any personal reasons, I'm simply not sure it's the right appro= ach. >=20 >=20 >=20 That sounds awesome. The WordPress Playground ships a copy of PHP compiled = to WASM, and it=E2=80=99s been an incredible journey realizing just what= =E2=80=99s capable with this technology. It=E2=80=99s really boosted the de= veloper experience working on WordPress itself and also that of those build= ing their own projects using WordPress. Some are already bringing in librar= ies like ffmpeg to convert images and media on the frontend, though it= =E2=80=99s sad that can=E2=80=99t also be done on the server yet. >=20 > Cheers, > Hammed >=20 >=20 >=20 Hope you have a nice weekend. Cheers. --=_636E1804-EA8C-44B6-A10E-3277151D3099 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w= 3.org/TR/REC-html40/loose.dtd"> <html> <head> <meta charset=3D"utf-8"> <style>body{font-family:-apple-system,Helvetica,Arial,sans-serif;}blockquot= e{margin:0;padding:0 0 0 12px;border-left:1px solid #aaa;color:#aaa;}hr.uni= box-forward{border:0;color:#888;background-color:#888;height:1px;}</style> </head> <body> <div>Hi Hammed, thank you for taking the time to read through this and shar= e your thoughts.</div> <div><br></div> <blockquote type=3D"cite"> <div>On Sep 19, 2024, at 1:41 PM, Hammed Ajao <hamiegold@gmail.com> w= rote:</div> <div><br></div> <div dir=3D"ltr" style=3D"caret-color: rgb(0, 0, 0); font-family: -webkit-s= tandard; font-variant-caps: normal; font-weight: 400; text-decoration: none= ;"> <br class=3D"Apple-interchange-newline"><br><div class=3D"gmail_quote"> <div dir=3D"ltr" class=3D"gmail_attr">On Tue, Sep 17, 2024 at 8:30=E2=80=AF= PM Dennis Snell <<a href=3D"mailto:dennis.snell@automattic.com" rel=3D"n= oreferrer" target=3D"_blank">dennis.snell@automattic.com</a>> wrote:<br> </div> <blockquote class=3D"gmail_quote" style=3D"margin: 0px 0px 0px 0.8ex; borde= r-left-width: 1px; border-left-style: solid; border-left-color: rgb(204, 20= 4, 204); padding-left: 1ex;"><div> <u></u><div> <div><br></div> <blockquote type=3D"cite"> <div>On Sep 17, 2024, at 2:03 PM, Rob Landers <rob@bottled.codes> wro= te:</div> <div><br></div> <div style=3D"font-family: -webkit-standard; font-variant-caps: normal; fon= t-weight: 400; text-decoration: none;"> <br><br> </div> <div style=3D"font-family: -webkit-standard; font-variant-caps: normal; fon= t-weight: 400; text-decoration: none;">On Tue, Sep 17, 2024, at 14:57, Adam= Zielinski wrote:<br> </div> <blockquote type=3D"cite" id=3D"m_6458481777469535973m_4230091655337564398m= _-3040290962447134337qt" style=3D"font-family: -webkit-standard; font-varia= nt-caps: normal; font-weight: 400; text-decoration: none;"><div dir=3D"ltr"> <div>> To summarize, I think PHP would benefit from:<br> </div> <div>><br> </div> <div>> 1. Adding WASM for simple low-level extensibility that could run = on<br> </div> <div>> shared hosts for things that are just not possible in PHP as desc= ribed a<br> </div> <div>> few paragraphs prior, and where we could enhance functionality ov= er time,<br> </div> <div>><br> </div> <div>> 2. Constantly improving PHP the language, which is what you are s= olely<br> </div> <div>> advocating for over extensibility,<br> </div> <div>Hi Mike,<br> </div> <div><br></div> <div>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.<br> </div> <div><br></div> <div>WebAssembly support in PHP core would be a huge security and productiv= ity improvement for the PHP and WordPress communities.<br> </div> <div><br></div> <div>> To summarize, I think PHP would benefit from:<br> </div> <div>><br> </div> <div>> 1. Adding WASM for simple low-level extensibility that could run = on<br> </div> <div>> shared hosts for things that are just not possible in PHP as desc= ribed a<br> </div> <div>> few paragraphs prior, and where we could enhance functionality ov= er time,<br> </div> <div><br></div> <div>Exactly this! With WASM, WordPress would get access to fast, safe, and= battle-tested libraries.<br> </div> <div><br></div> <div>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.<br> </div> <div><br></div> <div>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?<br> </div> <div><br></div> <div>> 2. Constantly improving PHP the language, which is what you are s= olely<br> </div> <div>> advocating for over extensibility,<br> </div> <div><br></div> <div>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.<br> </div> <div><br></div> <div>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.<br> </div> <div><br></div> <div>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.<br> </div> <div><br></div> <div>Also, here's a few interesting "WASM in PHP" projects I found = =E2=80=93 maybe they would be helpful:<br> </div> <div>- WebAssembly runtime built in PHP (!)<span>=C2=A0</span><a href=3D"ht= tps://github.com/jasperweyne/unwasm" rel=3D"noreferrer" target=3D"_blank">h= ttps://github.com/jasperweyne/unwasm</a><br> </div> <div>- WebAssembly runtime as a PHP language extension:<span>=C2=A0</span><= a href=3D"https://github.com/veewee/ext-wasm" rel=3D"noreferrer" target=3D"= _blank">https://github.com/veewee/ext-wasm</a><br> </div> <div>- WebAssembly runtime as a PHP language extension:<span>=C2=A0</span><= a href=3D"https://github.com/extism/php-sdk" rel=3D"noreferrer" target=3D"_= blank">https://github.com/extism/php-sdk</a><br> </div> <div><br></div> <div>[1]<span>=C2=A0</span><a href=3D"https://github.com/WordPress/wordpres= s-playground/" rel=3D"noreferrer" target=3D"_blank">https://github.com/Word= Press/wordpress-playground/</a><br> </div> <div>[2]<span>=C2=A0</span><a href=3D"https://github.com/WordPress/wordpres= s-playground/tree/trunk/packages/php-wasm/compile" rel=3D"noreferrer" targe= t=3D"_blank">https://github.com/WordPress/wordpress-playground/tree/trunk/p= ackages/php-wasm/compile</a><br> </div> <div>[3]<span>=C2=A0</span><a href=3D"https://developer.wordpress.org/refer= ence/classes/wp_html_processor/" rel=3D"noreferrer" target=3D"_blank">https= ://developer.wordpress.org/reference/classes/wp_html_processor/</a><br> </div> <div>[4]<span>=C2=A0</span><a href=3D"https://github.com/WordPress/wordpres= s-develop/pull/6713" rel=3D"noreferrer" target=3D"_blank">https://github.co= m/WordPress/wordpress-develop/pull/6713</a><br> </div> <div>[5]<span>=C2=A0</span><a href=3D"https://github.com/WordPress/blueprin= ts-library/blob/87afea1f9a244062a14aeff3949aae054bf74b70/src/WordPress/Zip/= ZipStreamReader.php" rel=3D"noreferrer" target=3D"_blank">https://github.co= m/WordPress/blueprints-library/blob/87afea1f9a244062a14aeff3949aae054bf74b7= 0/src/WordPress/Zip/ZipStreamReader.php</a><br> </div> <div>[6]<span>=C2=A0</span><a href=3D"https://github.com/WordPress/sqlite-d= atabase-integration/pull/157" rel=3D"noreferrer" target=3D"_blank">https://= github.com/WordPress/sqlite-database-integration/pull/157</a><br> </div> <div>[7]<span>=C2=A0</span><a href=3D"https://github.com/WordPress/blueprin= ts-library/blob/trunk/src/WordPress/AsyncHttp/Client.php" rel=3D"noreferrer= " target=3D"_blank">https://github.com/WordPress/blueprints-library/blob/tr= unk/src/WordPress/AsyncHttp/Client.php</a><br> </div> <div>[8]<span>=C2=A0</span><a href=3D"https://security.snyk.io/research/zip= -slip-vulnerability" rel=3D"noreferrer" target=3D"_blank">https://security.= snyk.io/research/zip-slip-vulnerability</a><br> </div> <div><br></div> <div>-Adam<br> </div> <div><br></div> <div><br></div> </div></blockquote> <div style=3D"font-family: -webkit-standard; font-variant-caps: normal; fon= t-weight: 400; text-decoration: none;"><br></div> <div style=3D"font-family: -webkit-standard; font-variant-caps: normal; fon= t-weight: 400; text-decoration: none;">Hey Adam,<br> </div> <div style=3D"font-family: -webkit-standard; font-variant-caps: normal; fon= t-weight: 400; text-decoration: none;"><br></div> <div style=3D"font-family: -webkit-standard; font-variant-caps: normal; fon= t-weight: 400; text-decoration: none;">I actually 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, a= nd while cool, nobody really could think of a use for it.<br> </div> <div style=3D"font-family: -webkit-standard; font-variant-caps: normal; fon= t-weight: 400; text-decoration: none;"><br></div> <div style=3D"font-family: -webkit-standard; font-variant-caps: normal; fon= t-weight: 400; text-decoration: none;">It seems like you have a use for it = though, and I=E2=80=99m reasonably certain you could get it working over ff= i 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 o= n those hosts.<br> </div> </blockquote> <div><br></div> <div>There are two major areas I have found that would benefit from having = a WASM runtime in PHP:</div> <div><br></div> <div>Obviously, being able to run the same algorithms on the frontend and b= ackend is a huge win for consistency in applications.<span class=3D"Apple-c= onverted-space">=C2=A0</span> </div> </div> </div></blockquote> <div><br></div> <div>I'm not convinced. That's what they said about nodejs(same algos and s= ame language on FE and BE). Except it's not really that consistent because = there are several discrepancies between the browser and node runtime. I'll = believe it when I see it.</div> </div> </div> </blockquote> <div><br></div> <div>There=E2=80=99s a note about this point that I think is worth calling = out, and that is something you probably already know, but JavaScript runtim= es provide a standard library while a WASM runtime is mostly just a virtual= machine. There=E2=80=99s also nothing provided that I=E2=80=99m aware of i= n WASM that offers filesystem access or network access, which are major are= as where in-browser JavaScript and NodeJS backends differ (because the brow= ser and server environments are fundamentally limited by different needs).<= /div> <div><br></div> <div>As things stand, projects are compiled into WebAssembly and literally = run identically in the different runtimes because it=E2=80=99s the bytecode= that=E2=80=99s specified, not specific functions or libraries. Whereas wit= h JavaScript we=E2=80=99re shipping source code and interacting with very d= ifferent systems, WASM bundles are a few steps removed from that, and have = no DOM or system access to interact with.</div> <div><br></div> <div>I=E2=80=99m fairly confident we can say that it=E2=80=99s non-controve= rsial that folks routinely run identical algorithms across different WASM r= untimes in different environments. As you mentioned elsewhere, it=E2=80=99s= very much akin to how Java and Closure and Scala all run on the JVM just f= ine together even being different languages, except in this case the runtim= e is an isolated sandbox by default with no external system access. WASM is= a lovely little VM, successful in ways many before it haven=E2=80=99t been= .</div> <div><br></div> <blockquote type=3D"cite"> <div dir=3D"ltr" style=3D"caret-color: rgb(0, 0, 0); font-family: -webkit-s= tandard; font-variant-caps: normal; font-weight: 400; text-decoration: none= ;"> <div class=3D"gmail_quote"> <div>=C2=A0</div> <blockquote class=3D"gmail_quote" style=3D"margin: 0px 0px 0px 0.8ex; borde= r-left-width: 1px; border-left-style: solid; border-left-color: rgb(204, 20= 4, 204); padding-left: 1ex;"><div><div><div>Particularly with text-related = algorithms it=E2=80=99s really easy for inconsistencies to develop due to t= he features available in each languages standard library, as well as due to= differences in how each language handles and processes string.</div></div>= </div></blockquote> <div><br></div> <div>I can see the appeal of that though.</div> <div><br></div> <blockquote class=3D"gmail_quote" style=3D"margin: 0px 0px 0px 0.8ex; borde= r-left-width: 1px; border-left-style: solid; border-left-color: rgb(204, 20= 4, 204); padding-left: 1ex;"><div><div> <div><br></div> <div>The other major area is similar, and we=E2=80=99ve seen this with the = HTML and XML parsing work recently undertaken in WordPress.</div> </div></div></blockquote> </div> </div> <div dir=3D"auto" style=3D"caret-color: rgb(0, 0, 0); font-family: -webkit-= standard; font-variant-caps: normal; font-weight: 400; text-decoration: non= e;"><br></div> <div dir=3D"auto" style=3D"caret-color: rgb(0, 0, 0); font-family: -webkit-= standard; font-variant-caps: normal; font-weight: 400; text-decoration: non= e;">Yeah you could talk about html parsing before 8.4 but with 8.4 we get l= exbor (thanks to niels) and that's as good as it gets. Php already has beau= tiful support for XML though so I'm not sure why you would implement a pars= er yourself.</div> </blockquote> <div><br></div> <div>It=E2=80=99s wonderful that PHP is finally getting a spec-compliant HT= ML DOM parser for the first time in its history, but \Dom\HTMLDocument is n= ot the right interface for every server need, and remains ill-suited for th= e kind of work typical in a WordPress site, which needs to run on low memor= y budgets, perform as fast as possible, and exceed the safety of what a gen= eric DOM parser produces (there are cases that \Dom\HTMLDocument will still= introduce vulnerabilities into an HTML document because it=E2=80=99s able = to create DOM trees that cannot be represented by HTML upon serialization, = and as it implements the HTML spec, it cannot prevent creating those trees)= . There are still a number of steps every developer needs to take to proper= ly setup the parser and get the right results back, and the parser has to l= oad the entire DOM tree into memory before any reads or manipulations can b= e performed on it.</div> <div><br></div> <div>WordPress=E2=80=99 HTML API is a near-zero memory overhead streaming H= TML parser designed around safe-by-default reading and writing of HTML whic= h requires no configuration or manual steps to get =E2=80=9Cthe right thing= .=E2=80=9D It=E2=80=99s also significantly slower in user-space PHP than it= needs to be. I hope one day that PHP has its own copy of this streaming pa= rser design, which is performant and available in every copy of PHP (which = is another issue with code only available in extensions), but even if that = never happens, running C or Rust code compiled to WebAssembly would provide= almost the same value as having that design implemented in the language.</= div> <div><br></div> <blockquote type=3D"cite"> <div dir=3D"ltr" style=3D"caret-color: rgb(0, 0, 0); font-family: -webkit-s= tandard; font-variant-caps: normal; font-weight: 400; text-decoration: none= ;"></div> <div dir=3D"auto" style=3D"caret-color: rgb(0, 0, 0); font-family: -webkit-= standard; font-variant-caps: normal; font-weight: 400; text-decoration: non= e;"><br></div> <div dir=3D"ltr" style=3D"caret-color: rgb(0, 0, 0); font-family: -webkit-s= tandard; font-variant-caps: normal; font-weight: 400; text-decoration: none= ;"><div class=3D"gmail_quote"><blockquote class=3D"gmail_quote" style=3D"ma= rgin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-style: solid; = border-left-color: rgb(204, 204, 204); padding-left: 1ex;"><div><div><div>T= here 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.</div></div></div></blockquote></div></div> <div dir=3D"ltr" style=3D"caret-color: rgb(0, 0, 0); font-family: -webkit-s= tandard; font-variant-caps: normal; font-weight: 400; text-decoration: none= ;"><div class=3D"gmail_quote"><blockquote class=3D"gmail_quote" style=3D"ma= rgin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-style: solid; = border-left-color: rgb(204, 204, 204); padding-left: 1ex;"><div><div><div>B= eing 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 impro= vement in runtime performance.</div></div></div></blockquote></div></div> <div dir=3D"auto" style=3D"caret-color: rgb(0, 0, 0); font-family: -webkit-= standard; font-variant-caps: normal; font-weight: 400; text-decoration: non= e;"><br></div> <div dir=3D"auto" style=3D"caret-color: rgb(0, 0, 0); font-family: -webkit-= standard; font-variant-caps: normal; font-weight: 400; text-decoration: non= e;">What exactly do you mean by jump into wasm? Like hand write it? Or you = mean jump into a language that can be compiled to wasm? How about debugging= at runtime? And if you mean better performance than PHP, while that is lik= ely, it isn't guaranteed. PHP is pretty fast and will be faster for some ro= utines that are optimized by the engine. Wasm will never be as fast as exte= nsions though because with extensions, all you're doing is extending the en= gine. Same as any internal extension. With wasm you're interoperating with = an entirely separate VM.</div> </blockquote> <div><br></div> <div>By jumping into WASM I=E2=80=99m talking about the second thing you me= ntion: calling functions written in languages compiled to WebAssembly. Even= with the overhead of marshaling data, the things that WebAssembly is good = at are the things that PHP is slow at: specifically things like raw numeric= computation and string manipulation and parsing. I write a lot of parsing = code and frequently am surprised at the overhead cost of string processing = and array operations in PHP. There are a number of straightforward operatio= ns available in C that just can=E2=80=99t be done in PHP. I don=E2=80=99t s= ee this as a failing of PHP, just an aspect of how it is.</div> <div><br></div> <div>For runtime debugging I don=E2=80=99t have any particular thoughts. I= =E2=80=99m not aware of anyone who has ever tried to runtime debug CURL cal= ls or things like `mb_convert_encoding()`. Functions invoked in the WASM ru= ntime would more or less be library functions, like `ffmpeg`. Debugging wou= ld likely most frequently be done as a library and dumped into the PHP appl= ication with no expectation for debugging.</div> <div><br></div> <div>Effectively these are user-space PHP extensions, and are very convenie= nt because they can be updated without recompiling PHP or begging web hosts= to update their PHP version, or to do that every other Tuesday, or wheneve= r another security exploit is fixed in some image processor. On that note, = the ability to sandbox image processing code (and any other user-provided c= ontent) is a huge perk. Many of the exploits of past PHP extensions could b= e contained inside the VM, which has limited ability to reach out into the = system. Fixing vulnerabilities and bugs becomes something any auto-updater = can accomplish, requiring no effort or interaction on the part of the host.= </div> <div><br></div> <blockquote type=3D"cite"> <div dir=3D"auto" style=3D"caret-color: rgb(0, 0, 0); font-family: -webkit-= standard; font-variant-caps: normal; font-weight: 400; text-decoration: non= e;"><br></div> <div dir=3D"ltr" style=3D"caret-color: rgb(0, 0, 0); font-family: -webkit-s= tandard; font-variant-caps: normal; font-weight: 400; text-decoration: none= ;"><div class=3D"gmail_quote"><blockquote class=3D"gmail_quote" style=3D"ma= rgin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-style: solid; = border-left-color: rgb(204, 204, 204); padding-left: 1ex;"><div dir=3D"auto= ">Additionally, it=E2=80=99s a perk being able to write such algorithms in = languages that aid that development through more powerful type systems.</di= v></blockquote></div></div> <div dir=3D"auto" style=3D"caret-color: rgb(0, 0, 0); font-family: -webkit-= standard; font-variant-caps: normal; font-weight: 400; text-decoration: non= e;"><br></div> <div dir=3D"auto" style=3D"caret-color: rgb(0, 0, 0); font-family: -webkit-= standard; font-variant-caps: normal; font-weight: 400; text-decoration: non= e;">We can agree on that. But I use C++ for my extensions so there's also t= hat.</div> <div dir=3D"auto" style=3D"caret-color: rgb(0, 0, 0); font-family: -webkit-= standard; font-variant-caps: normal; font-weight: 400; text-decoration: non= e;"><br></div> <div dir=3D"ltr" style=3D"caret-color: rgb(0, 0, 0); font-family: -webkit-s= tandard; font-variant-caps: normal; font-weight: 400; text-decoration: none= ;"><div class=3D"gmail_quote"><blockquote class=3D"gmail_quote" style=3D"ma= rgin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-style: solid; = border-left-color: rgb(204, 204, 204); padding-left: 1ex;"><div dir=3D"auto= ">There=E2=80=99s additional value in a number of other separate tasks. Con= verting images or generating thumbnails is a good example where raw perform= ance is less of a concern than being able to ensure that the image library = is available and not exposing the host system to risk.<span class=3D"Apple-= converted-space">=C2=A0</span> </div></blockquote></div></div> <div dir=3D"auto" style=3D"caret-color: rgb(0, 0, 0); font-family: -webkit-= standard; font-variant-caps: normal; font-weight: 400; text-decoration: non= e;"><br></div> <div dir=3D"auto" style=3D"caret-color: rgb(0, 0, 0); font-family: -webkit-= standard; font-variant-caps: normal; font-weight: 400; text-decoration: non= e;">Imo this is where FFI should shine but I'll admit that the current impl= ementation is lacking in both security and functionality.</div> <div dir=3D"auto" style=3D"caret-color: rgb(0, 0, 0); font-family: -webkit-= standard; font-variant-caps: normal; font-weight: 400; text-decoration: non= e;"><br></div> <div dir=3D"auto" style=3D"caret-color: rgb(0, 0, 0); font-family: -webkit-= standard; font-variant-caps: normal; font-weight: 400; text-decoration: non= e;"><br></div> <div dir=3D"ltr" style=3D"caret-color: rgb(0, 0, 0); font-family: -webkit-s= tandard; font-variant-caps: normal; font-weight: 400; text-decoration: none= ;"><div class=3D"gmail_quote"><blockquote class=3D"gmail_quote" style=3D"ma= rgin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-style: solid; = border-left-color: rgb(204, 204, 204); padding-left: 1ex;"><div dir=3D"auto= ">I imagine plenty of =E2=80=9CPHP lite-extensions=E2=80=9D appearing in th= is space because it would give people the opportunity to experiment with fe= atures that are impractical in user-space PHP before fully committing the l= anguage itself to that interface or library. It would extend the reach of P= HP=E2=80=99s usability because it would make possible for folks, who happen= to be running on cheap shared hosts, to run more complicated processing ta= sks 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 generally to people without the same full control over their= stack.</div></blockquote></div></div> <div dir=3D"auto" style=3D"caret-color: rgb(0, 0, 0); font-family: -webkit-= standard; font-variant-caps: normal; font-weight: 400; text-decoration: non= e;"><br></div> <div dir=3D"auto" style=3D"caret-color: rgb(0, 0, 0); font-family: -webkit-= standard; font-variant-caps: normal; font-weight: 400; text-decoration: non= e;">Shared hosting for php gets you the worst possible version of php. </di= v> </blockquote> <div><br></div> <div>Couldn=E2=80=99t have said it better myself!</div> <div><br></div> <blockquote type=3D"cite"><div dir=3D"auto" style=3D"caret-color: rgb(0, 0,= 0); font-family: -webkit-standard; font-variant-caps: normal; font-weight:= 400; text-decoration: none;">Can't recompile to enable any bundled extensi= on, can't install any new extensions, so how exactly would you approach thi= s? Wasm bundled with the engine by default? Or some kind of opt in mechanis= m that shared hosters won't even be able to use?</div></blockquote> <div><br></div> <div>As with many of the things I=E2=80=99ve been writing on this list late= ly, to me, an embedded WASM runtime makes most sense as a central language = feature and available everywhere PHP is deployed. There are a few core basi= c subsystems that either are foundational to the environment PHP operates i= n (for example, web-related technologies like HTTP and HTML and URLs) or wh= ich bring so much value to the language that it opens up brand new paradigm= s or potentially removes major maintenance burdens.</div> <div><br></div> <div>If we could ship `imagemagick` as a WASM extension there would be no n= eed for the `imagemagick` extension. The security environment out of the bo= x is so much better; it=E2=80=99s not worth the lost potential for performa= nce that a native extension offers. Someone may not agree with this, and th= at=E2=80=99s fine because they can always install a native extension or uti= lize the FFI on infrastructure they control.</div> <div><br></div> <div>I think at times WordPress sees a very different picture of the world = than many great PHP projects see. Our reality is that we=E2=80=99re writing= code that runs on hardware we don=E2=80=99t control or even know about. We= cannot in any way install or force certain extensions to be present. The w= orst possible version of PHP is literally the constraint at which we are al= lowed to code. Anything beyond that and we can=E2=80=99t ship it because a = large fraction of the internet will start crashing. It=E2=80=99s frustratin= g, but also an honor to be able to ensure that people who can=E2=80=99t aff= ord high end servers can still build their own place on the world wide web.= </div> <div><br></div> <div>Over the past several years, though, WordPress has also been a positiv= e influence on persuading hosts to update their PHP versions, because PHP h= as gotten better enough that the argument is easy: upgrade to PHP 7 and you= r data center costs will drop X%. It=E2=80=99s not too hard to imagine winn= ing similarly on the security argument.</div> <div><br></div> <div>WASM code on memory-constrained, oversubscribed, CPU-poor hosts is sti= ll considerably better for certain kinds of computation than user-space PHP= code on memory-constrained, oversubscribed, CPU-poor hosts.</div> <div><br></div> <blockquote type=3D"cite"> <div dir=3D"auto" style=3D"caret-color: rgb(0, 0, 0); font-family: -webkit-= standard; font-variant-caps: normal; font-weight: 400; text-decoration: non= e;"><br></div> </blockquote> <blockquote type=3D"cite"> <div dir=3D"ltr" style=3D"caret-color: rgb(0, 0, 0); font-family: -webkit-s= tandard; font-variant-caps: normal; font-weight: 400; text-decoration: none= ;"><div class=3D"gmail_quote"> <blockquote class=3D"gmail_quote" style=3D"margin: 0px 0px 0px 0.8ex; borde= r-left-width: 1px; border-left-style: solid; border-left-color: rgb(204, 20= 4, 204); padding-left: 1ex;"> <div dir=3D"auto"><br></div> <blockquote type=3D"cite"> <div style=3D"font-family: -webkit-standard; font-variant-caps: normal; fon= t-weight: 400; text-decoration: none;"></div> <div style=3D"font-family: -webkit-standard; font-variant-caps: normal; fon= t-weight: 400; text-decoration: none;"><br></div> <div style=3D"font-family: -webkit-standard; font-variant-caps: normal; fon= t-weight: 400; text-decoration: none;">However, plugins basically work via = hooks/filters. So as long as you register the right listeners and handle se= rialization properly, you can simply run a separate process for the plugin,= or call a socket for =E2=80=9Cremote=E2=80=9D plugins.<br> </div> <div style=3D"font-family: -webkit-standard; font-variant-caps: normal; fon= t-weight: 400; text-decoration: none;"><br></div> <div style=3D"font-family: -webkit-standard; font-variant-caps: normal; fon= t-weight: 400; text-decoration: none;">I don=E2=80=99t see anything stoppin= g anyone from implementing that today.</div> <div style=3D"font-family: -webkit-standard; font-variant-caps: normal; fon= t-weight: 400; text-decoration: none;"><br></div> <div id=3D"m_6458481777469535973m_4230091655337564398m_-3040290962447134337= sig121229152" style=3D"font-family: -webkit-standard; font-variant-caps: no= rmal; font-weight: 400; text-decoration: none;">=E2=80=94 Rob</div> </blockquote> <div dir=3D"auto"><br></div> <div dir=3D"auto">I=E2=80=99m excited to see this conversation. I=E2=80=99v= e wanted to propose it a number of times myself.</div> <div dir=3D"auto"><br></div> <div dir=3D"auto">Warmly,</div> <div dir=3D"auto">Dennis Snell=C2=A0</div> </blockquote> <div><br></div> <div>I actually love wasm, I'm currently in the process of compiling my min= i php runtime to wasm (basically a browser only version of 3v4l). I'm not a= gainst this for any personal reasons, I'm simply not sure it's the right ap= proach.</div> </div></div> </blockquote> <div><br></div> <div>That sounds awesome. The WordPress Playground ships a copy of PHP comp= iled to WASM, and it=E2=80=99s been an incredible journey realizing just wh= at=E2=80=99s capable with this technology. It=E2=80=99s really boosted the = developer experience working on WordPress itself and also that of those bui= lding their own projects using WordPress. Some are already bringing in libr= aries like ffmpeg to convert images and media on the frontend, though it= =E2=80=99s sad that can=E2=80=99t also be done on the server yet.</div> <div><br></div> <blockquote type=3D"cite"> <div dir=3D"ltr" style=3D"caret-color: rgb(0, 0, 0); font-family: -webkit-s= tandard; font-variant-caps: normal; font-weight: 400; text-decoration: none= ;"><div class=3D"gmail_quote"> <div> <br>Cheers,</div> <div>Hammed</div> </div></div> </blockquote> <div><br></div> <div>Hope you have a nice weekend. Cheers.</div> </body> </html> --=_636E1804-EA8C-44B6-A10E-3277151D3099--