Skip to content

Support multiple PHP versions #94

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

Merged
merged 17 commits into from
Dec 28, 2022
Merged

Support multiple PHP versions #94

merged 17 commits into from
Dec 28, 2022

Conversation

adamziel
Copy link
Collaborator

@adamziel adamziel commented Dec 20, 2022

Adds support for more PHP versions and a php query parameter to switch between them. For example:

/wordpress.html?php=5.6:

CleanShot 2022-12-28 at 22 20 59@2x

Supported PHP versions: 5.6, 7.0, 7.1, 7.2, 7.3, 7.4, 8.0, 8.1, 8.2

Adds support for the `php` query string option that may be used to switch between PHP versions. For example:

/wordpress.html?php=8.1

Supported versions: 8.0, 8.1, 8.2
@adamziel
Copy link
Collaborator Author

adamziel commented Dec 20, 2022

Problems with this PR:

  • The php-{version}.js module produced by this PR lack the ES module wrapper and proper export (blocker)
  • PHP 7.4 could potentially be supported with minimal changes (could be a follow-up PR to keep things moving)

Edit: Both issues are now addressed

@adamziel adamziel mentioned this pull request Dec 20, 2022
@adamziel
Copy link
Collaborator Author

This one is ready!

@adamziel adamziel merged commit 25c7cfd into trunk Dec 28, 2022
@adamziel adamziel deleted the multiple-php-versions branch December 28, 2022 21:26
bgrgicak added a commit that referenced this pull request May 7, 2025
## Motivation for the change, related issues

This PR adds `statfs` support to the Emscripten root file system to
enable PHP-wasm Node to get real filesystem stats for the `/` path.

Currently, in PHP-wasm Node, PHP functions like `disk_total_space('/')`
return the default hardcoded value for MEMFS instead of the actual disk
space.

This happens because Emscripten automatically detects the filesystem for
a given path, and because the root path always uses the MEMFS
filesystem, Emscripten will use the MEMFS `statfs` implementation.

PHP-wasm Node includes two Emscripten filesystems, MEMFS and NODEFS.
MEMFS doesn't have access to the operating system's filesystem, so it
can only return a hardcoded value.
NODEFS has access to the OS filesystem through the `fs` module, and
specifically for `statfs` it uses `fs.statfsSync` to get real data.

## Implementation details

This PR uses Emscripten's `onRuntimeInitialized` event to override the
`statfs` implementation in the Emscripten root FS with the NODEFS
implementation of `statfs`.

It also defines the `FS.root.mount.opts.root` path as `.` to ensure the
root node has a path value defined.
Otherwise when we call `FS.statfs('/')` it would use the root node's
root path which is `undefined` and this would throw an error because it
would call `fs.statfsSync(undefined)` in the NODEFS implementation of
`statfs`.

I explored fixing this [issue in
Emscripten](emscripten-core/emscripten#23912),
but I wasn't able to find a working solution there, so I ended up
patching it in Playground.

## Testing Instructions (or ideally a Blueprint)

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

Successfully merging this pull request may close these issues.

1 participant