Expand description
bext-php — embedded PHP runtime for the bext server.
Provides in-process PHP execution via a custom SAPI that bridges PHP’s I/O to Rust. Architecture follows the same pattern as FrankenPHP (custom SAPI + worker threads) but uses Rust FFI instead of Go/CGo.
§How it works
-
build.rscompilessapi/bext_php_sapi.cand links againstlibphp(PHP compiled with--enable-embed --enable-zts). -
The C SAPI implements PHP’s
sapi_module_structcallbacks, forwarding all I/O (output writes, POST reads, cookies, headers) to Rust viaextern "C"functions defined inffi.rs. -
PhpPoolmanages N OS threads, each registered with PHP’s TSRM. Requests are dispatched via bounded channels (same asJscRenderPool). -
PhpStateis the top-level handle added to bext-server’sAppState. It manages initialization, pool lifecycle, and graceful shutdown.
§Requirements
- PHP 8.2+ compiled with
--enable-embed --enable-zts php-configin PATH (or setBEXT_PHP_CONFIG)- Linux (primary target) or macOS
§Configuration
[php]
enabled = true
document_root = "./public"
workers = 4
[php.ini]
memory_limit = "256M"
opcache.enable = "1"
opcache.jit = "1255"Re-exports§
pub use config::PhpConfig;pub use pool::PhpPool;pub use pool::PhpPoolStats;pub use pool::PhpResponse;
Modules§
- bridge
- Shared memory bridge — bidirectional PHP ↔ JSC communication.
- config
- PHP runtime configuration.
- context
- Per-request context for PHP script execution.
- pool
- PHP Worker Pool — dedicated OS threads for PHP script execution.
Structs§
- PhpState
- Central state for the embedded PHP runtime.