PHP Toolkit

Experimental performance preview

Native APIs for the hottest toolkit paths.

The Native APIs extension registers PHP extension classes for high-volume HTML, XML, and URL-in-text workloads. Public toolkit classes keep their PHP fallback behavior, so projects can try native acceleration without making the extension a hard dependency.

Status

Experimental: the extension is useful for testing and benchmarking, but the packaging, release cadence, and accelerated surface are still evolving. Use immutable release manifests for reproducible Playground links.

When the extension is loaded before the toolkit, wrappers may delegate covered operations to native classes. If the extension is missing, incompatible, or disabled with WP_NATIVE_APIS_DISABLE_DEFAULTS, the same public APIs continue through pure PHP implementations.

What it accelerates

HTML

Fast tag scans, fragment parsing, batch queries, and aggregate audits for common WP_HTML_Tag_Processor and fragment-processor workloads.

HTML reference →

XML

Streaming XML token, tag, namespace, attribute, and inventory summaries for export-sized documents without building a DOM tree.

XML reference →

URL-in-text

A native candidate scanner for plain-text URL detection, while public URL handling still validates candidates through the existing WHATWG parser path.

DataLiberation reference →

Two release targets

Host PHP extension

The Rust-backed extension is built with ext-php-rs for a specific host PHP ABI. A Linux PHP 8.3 build cannot be reused for PHP 8.4 or PHP 8.5.

Build and verify locally →

PHP.wasm extension for Playground

Browser Playground loads a PHP.wasm side module through the php-extension URL parameter before PHP starts. The current Playground bundle is a smoke-testable extension path and should not be described as full Rust-backed host parity.

Open release index →

Test the latest Playground build

The smoke-test Blueprint writes a small PHP landing page into WordPress Playground. It checks that the native classes were registered before PHP started, runs a few representative operations, and shows quick browser-side timing numbers.

  1. Open the Playground URL with php=8.4 and the latest wp_native_apis manifest.
  2. Wait for the Blueprint to open /native-api-smoke.php.
  3. Confirm the page says wp_native_apis WASM extension loaded, then review the timing cards.

Test in Playground →

Benchmarks

The release workflow also builds the host Rust-backed extension and runs the repository benchmark harness against the same workloads in PHP and native modes. The release page publishes raw JSON plus a summarized view with wall-clock speedups.

php -d extension=extensions/native-apis/target/release/libwp_native_apis.so \
	bin/benchmark-native-apis.php --iterations=50 --mode=both --disable-native-defaults --require-native

Benchmark numbers are machine- and workflow-run-specific. Treat them as directional evidence for which workflows benefit from native batching, not as universal throughput guarantees.