Skip to content

Run legacy WordPress versions on PHP 5.6 compiled to WebAssembly#3386

Draft
wp-playground-bot wants to merge 3 commits intoWordPress:trunkfrom
wp-playground-bot:pr-3284
Draft

Run legacy WordPress versions on PHP 5.6 compiled to WebAssembly#3386
wp-playground-bot wants to merge 3 commits intoWordPress:trunkfrom
wp-playground-bot:pr-3284

Conversation

@wp-playground-bot
Copy link

@wp-playground-bot wp-playground-bot commented Mar 13, 2026

Summary

WordPress Playground currently supports PHP 7.4 through 8.5, but early WordPress releases (1.x through 4.x) require PHP 5.x. This PR compiles PHP 5.6.40 to WebAssembly and integrates it into the Playground runtime, unlocking the ability to run WordPress all the way back to version 1.0.

PHP 5.6 is backward compatible with PHP 5.2, so a single legacy build covers every older WordPress release that needs PHP 5.x.

What changed

The Dockerfile and C source extensions gained PHP 5.x version guards and compatibility stubs so the existing Emscripten build pipeline can produce PHP 5.6 binaries. Extensions like proc_open, dns_polyfill, post_message_to_js, and wasm_memory_storage were ported to work with the older Zend API.

New node-builds/5-6 and web-builds/5-6 packages provide the compiled WASM binaries (asyncify and JSPI variants), with the corresponding loader module wiring in both @php-wasm/node and @php-wasm/web.

A LegacyPHPVersions export keeps the 5.6 version separate from the main SupportedPHPVersions list so existing tests and UI aren't affected. A dedicated test suite (legacy-php-versions.spec.ts) covers version verification, file I/O, networking, proc_open, SQLite, JSON, sessions, mbstring, error handling, memory, and filesystem.

Supersedes #3284.

Test plan

  • Existing PHP 7.4–8.5 tests still pass
  • Legacy PHP 5.6 test suite passes
  • TypeScript typecheck passes
  • WordPress 4.x, 3.x, 2.x, 1.x boot successfully on PHP 5.6

Enable compiling PHP 5.6 to WebAssembly so WordPress Playground can run
WordPress 1.x through 4.x, which require PHP 5.2+. PHP 5.6 is backward
compatible with PHP 5.2 code, so a single legacy version covers all older
WordPress releases.

Changes:
- Dockerfile: Add PHP 5.x version guards (fiber-asm, imagick, chunk-alloc
  patches, ASM arithmetic, cli_server)
- C sources: Add PHP 5.x compatibility for proc_open, dns_polyfill,
  post_message_to_js, and wasm_memory_storage extensions
- Package scaffolding: node-builds/5-6 and web-builds/5-6 with full NX
  project configuration
- Loader modules: Add case '5.6' to node and web getPHPLoaderModule()
- Version registry: Add PHP 5.6 to supported-php-versions.mjs and
  LegacyPHPVersions in supported-php-versions.ts (separate from
  SupportedPHPVersions to avoid test regressions)
- Test suite: Dedicated legacy-php-versions.spec.ts with 12 tests
  covering execution, file I/O, networking, proc_open, SQLite, JSON,
  sessions, mbstring, error handling, memory, and filesystem ops
- tsconfig.base.json: Path aliases for new packages

Note: WASM binaries must be compiled in a Docker-enabled environment:
  node packages/php-wasm/compile/build.js --PLATFORM=node --PHP_VERSION=5.6 \
    --WITH_IMAGICK=no --WITH_OPCACHE=no

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
PHP 5.6 is now functional in Playground with both web JSPI and node
asyncify variants. This required fixing several compatibility issues
between PHP 5.6's C codebase and modern Emscripten/clang:

Dockerfile: SQLite duplicate symbol fix for PHP 5.x bundled sqlite3,
readdir_r compatibility, x86_64 inline assembly guards, PCRE JIT
disable, curl-config shim for PHP 5.x detection, and compiler warning
suppression flags (-Wno-implicit-int, -Wno-implicit-function-declaration,
-Wno-incompatible-function-pointer-types, etc).

php_wasm.c: PHP 5.x API compat for size_t vs int return types in
SAPI callbacks, and dup parameter in add_next_index_stringl /
RETVAL_STRINGL macros.

The test suite's isVersionBuilt() now checks for actual .wasm binary
files instead of just directory existence, preventing crashes when
placeholder stubs are present but no real binaries exist.

Built with limited extensions (no OpenSSL, cURL, GD, ImageMagick,
MySQL, mbregex) for this initial release. Verified: PHP boots,
initializes SAPI, serves HTTP 200 with X-Powered-By: PHP/5.6.40,
and executes PHP code producing correct output.
Resolved three merge conflicts:
- packages/php-wasm/supported-php-versions.mjs: Kept PR's newer version numbers and PHP 5.6 entry
- packages/php-wasm/node/project.json: Kept both test-legacy-php (PR) and test-file-locking targets (trunk)
- packages/php-wasm/node/src/lib/load-runtime.ts: Merged LegacyPHPVersion import with trunk's new imports, kept modernVersion cast with trunk's truthy check
@wp-playground-bot wp-playground-bot changed the title Pr 3284 Run legacy WordPress versions on PHP 5.6 compiled to WebAssembly Mar 14, 2026
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.

2 participants