-
Notifications
You must be signed in to change notification settings - Fork 368
Draft: Support dynamic loading of PHP extensions via dlopen #673
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
Conversation
…playground into sm-reinstantiation
…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.soFile.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 |
…#2326) ## Motivation for the change This is a pull request to dynamically load Xdebug in `@php-wasm` Node ASYNCIFY. [Roadmap](#2315) ## Related issues and pull requests Relative to XDebug - #2248 - #314 - #2288 - #831 Relative to dynamic library - #89 - #2290 - #673 ## Implementation details Additional steps for asyncify are implemented : - new nx commands - new `WITH_JSPI` and `WITH_DEBUG` arguments in Xdebug Dockerfile - new `xdebug.so` files are compiled and dynamically loaded ## Zend extensions and PHP versions > [!IMPORTANT] > Each version of PHP requires its own version of Xdebug because each version of PHP has a specific Zend Engine API version. Consequently, each version of Xdebug is designed to be compatible with a particular Zend Engine API version. Example using PHP `8.2` with Xdebug `8.3` : ``` Xdebug requires Zend Engine API version 420230831. The Zend Engine API version 420220829 which is installed, is outdated. ``` ## Testing Instructions Two files are needed. A PHP file to test the step debugger. A JS file to run PHP 8.4 node ASYNCIFY. `php/xdebug.php` ```php <?php $test = 42; // Set a breakpoint on this line echo "Hello Xdebug World\n"; ``` `scripts/node.js` ```javascript import { PHP } from '@php-wasm/universal'; import { loadNodeRuntime } from '@php-wasm/node'; const php = new PHP( await loadNodeRuntime( '8.4', { withXdebug : true } ) ); await php.runStream( { scriptPath : `php/xdebug.php` } ); ``` To achieve the test, you first need to start debugging [ with F5 or Run > Start debugging in VSCode ], then run : ```bash node scripts/node.js ```

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.inifile with the following contents:Finally, run:
Here's what you should see:
Remaining work
php.jsfiles as mentioned in the comments below.sofiles:php.jsfile (they inflate the code from 200KB to 5MB)Follow-up work