Skip to content
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

Lazy load PHP extensions (like dom and libxml) #89

Open
westonruter opened this issue Dec 15, 2022 · 8 comments
Open

Lazy load PHP extensions (like dom and libxml) #89

westonruter opened this issue Dec 15, 2022 · 8 comments

Comments

@westonruter
Copy link
Member

I tried uploading the Web Stories plugin, but the plugin gave an error notice:

The following PHP extensions are missing: dom, libxml. Please contact your host to finish installation. The following PHP classes are missing: DOMAttr, DOMComment, DOMDocument, DOMElement, DOMNode, DOMNodeList, DOMText, DOMXPath. Please contact your host to finish installation. The following PHP functions are missing: libxml_use_internal_errors, libxml_clear_errors. Please contact your host to finish installation.

The dom and libxml extensions should be enabled, as they are almost always available on WordPress sites.

@westonruter
Copy link
Member Author

I suppose that means the WITH_LIBXML build option should rather be yes here:

'--build-arg',
`WITH_LIBXML=no`,

@adamziel
Copy link
Collaborator

adamziel commented Dec 16, 2022

@westonruter It's been enabled by default, I disabled it to remove 1.21M from the bundle size (see #2).

I do agree it can be useful, though! That's the problem of different use-cases – you don't need it for embeddable code snippets in a JavaScript-oriented WordPress course, but you do need it to use the Playground with certain WordPress plugins.

An obvious solution would be hosting two PHP builds, with and without libxml, and having a configuration switch with some smart defaults. It would work as long as that's only about a single extension. For two, three, or five PHP extensions there would need to be something smarter. Perhaps pre-packaged "environments" for specific purposes? As in:

  • Bare-minimum PHP for optimal bundle size
  • All-in-one PHP with all the supported extensions
  • A few targeted middle-ground environments with opinionated sets of extensions

@swissspidy
Copy link
Member

This list of recommended extensions might be helpful: https://make.wordpress.org/hosting/handbook/server-environment/#php-extensions

@adamziel
Copy link
Collaborator

adamziel commented Jan 31, 2023

Another idea: Emscripten supports dynamic libraries that are loaded lazily – Playground could use them to provide a lean initial bundle while also offering all the additional features.

@adamziel adamziel changed the title Enable dom and libxml extensions by default Lazy load extensions like dom and libxml Apr 11, 2023
@adamziel
Copy link
Collaborator

Here’s v8.dev article about an unrelated topic with an example implementation of lazy-loading wasm libraries. They use the experimental JSPI api, but it should also work with the existing stable Asyncify api:

https://v8.dev/blog/jspi

@adamziel
Copy link
Collaborator

@adamziel adamziel changed the title Lazy load extensions like dom and libxml Lazy load PHP extensions (like dom and libxml) Jun 2, 2023
@adamziel
Copy link
Collaborator

adamziel commented Oct 9, 2023

Actually – lazy loading may not be needed at all. Building PHP extensions to .so files and loading them using zend_extension= in PHP.ini would already do the trick. Blueprints would then support declaring a list of extensions to load and voila.

I just explored that today and managed to build XDebug. The next challenge is actually loading it in PHP, dlopen seems to be disabled at the moment.

@adamziel
Copy link
Collaborator

adamziel commented Oct 9, 2024

JSPI support just got merged and lazy loading is now technically possible – as described in https://v8.dev/blog/jspi.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants