-
Notifications
You must be signed in to change notification settings - Fork 275
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft: Support dynamic loading of PHP extensions via dlopen #673
Conversation
…playground into sm-reinstantiation
Add `require_once "/wordpress/wp-load.php";` to Blueprint examples in the documentation to clarify how to call WordPress functions.
…ce worker (#668) ## What is this PR doing? Patches the block editor to use a special ControlledIframe component instead of a regular HTML "iframe" element. The goal is to make the iframe use a plain HTTP URL instead of srcDoc, blob URL and other variations. Normally, the patch applied here would be a huge maintenance burden over time. However, @ellatrix explores fixing the issue upstream [in the Gutenberg repo](#646). Once her PR is merged, the patch here will only be needed for a known and limited set of WordPress and Gutenberg versions and will not require ongoing reconciliation with new WP/GB releases. Fixes #646 ## What problem is it solving? In Playground, the editor iframe needs to be controlled by Playground's service worker so it can serve CSS and other static assets. Otherwise all the requests originating in that iframe will yield 404s. However, different WordPress versions use a variety of iframe techniques that result in a non-controlled iframe: * 6.3 uses a binary blob URL and the frame isn't controlled by a service worker * <= 6.2 uses srcdoc had a null origin and the frame isn't controlled by a service worker * Other dynamic techniques, such as using a data URL, also fail to produce a controlled iframe HTTP URL src like src="/doc.html" seems to be the only way to create a controlled iframe. And so, this commit ensures that the block editor iframe uses a plain HTTP URL regardless of the WordPress version. Once WordPress/gutenberg#55152 lands, this will just work in WordPress 6.4 and new Gutenberg releases. ## Testing Instructions Run `npm run dev` Then, confirm the inserter is nicely styled and there are no CSS-related 404s in the network tools. Test the following editors: * Post editor http://localhost:5400/website-server/?url=/wp-admin/post-new.php * Site editor http://localhost:5400/website-server/?url=/wp-admin/site-editor.php * For all supported WordPress versions * With and without the Gutenberg plugin (`&plugin=gutenberg`) ## Related * https://bugs.chromium.org/p/chromium/issues/detail?id=880768 * https://bugzilla.mozilla.org/show_bug.cgi?id=1293277 * w3c/ServiceWorker#765 * #42 * b7ca737
I was able to build shared However, that seemed to also have enabled them by default when starting PHP and now it complains about undefined xml symbols. Perhaps building PHP twice is needed here? One time to generate these shared libraries, and another time to build a version that doesn't try to load them unless explicitly configured via Edit: It worked for mbstring! php.ini: extension=/Users/cloudnik/www/Automattic/core/plugins/playground/packages/php-wasm/node/public/mbstring.so File.php: var_dump(mb_convert_case('zażółć gęślą jaźń', MB_CASE_UPPER, 'UTF-8')); However, it didn't work for gd.so:
Sounds like we'd need to load Edit: I patched + if (!global.hookedIntoWasmLoading) {
+ global.hookedIntoWasmLoading = true;
+ metadata.neededDynlibs.push(
+ 'libpng16.so'
+ );
+ console.log(metadata.neededDynlibs);
+ }
metadata.neededDynlibs.forEach((needed) => loadDynamicLibrary(needed, flags, localScope));
return loadModule();
} Edit: The cc @seanmorris |
Adds support for loading arbitrary PHP extensions in the web version of Playground using all three available APIs: * Query API: `?php-extension=gd&php-extension=xml-bundle` * Blueprints: `{ "phpExtensions": [ "gd", "xml-bundle" ] }` * JavaScript API: `WebPHP.loadSync(phpVersion, { extensions: ["gd", "xml-bundle"]})` For now, it only switches between a barebones ~6MB PHP build and a larger ~8MB with more extensions included. In the future, the internal implementation will change and PHP extensions will be shipped and downloaded separately – see #673 1. Click the new "Load PHP extensions" checkbox in the configuration modal 2. Go to /phpinfo.php and confirm that `gd`, `xml`, and `mbstring` extensions are now available 3. Uncheck that checkbox 4. Confirm these extensions are no longer loaded
Adds support for loading arbitrary PHP extensions in the web version of Playground using all three available APIs: * Query API: `?php-extension-bundle=kitchen-sink` * Blueprints: `{ "phpExtensionBundles": [ "kitchen-sink" ] }` For now, it only switches between a barebones ~6MB PHP build and a larger ~8MB with more extensions included. In the future, the internal implementation will change and PHP extensions will be shipped and downloaded separately – see #673 1. Click the new "Load PHP extensions" checkbox in the configuration modal 2. Go to /phpinfo.php and confirm that `gd`, `xml`, and `mbstring` extensions are now available 3. Uncheck that checkbox 4. Confirm these extensions are no longer loaded <img width="1251" alt="CleanShot 2023-10-11 at 19 50 14@2x" src="https://github.com/WordPress/wordpress-playground/assets/205419/4f341a98-6a3a-4b01-b406-03d3e2834a20"> Solves #655 cc @dmsnell @danielbachhuber @seanmorris
I just force-pushed. The previous HEAD was c24c153 |
Something with git history got very wrong here and I'm not investing more time into untangling it. Let's close this PR and continue in #831 |
What is this PR doing?
Explores support for dynamic loading of PHP extensions.
Related to #314, #655, #89
Minimal dlopen example without PHP involved.
Testing instructions
Clone this branch to a directory with path
/Users/cloudnik/www/Automattic/core/plugins/playground-2/wordpress-playground
. It's not great, I know. I want to remove the explicit path dependency soon.Then, create a
/usr/local/etc/php.ini
file with the following contents:Finally, run:
Here's what you should see:
Remaining work
php.js
files as mentioned in the comments below.so
files:php.js
file (they inflate the code from 200KB to 5MB)Follow-up work