Skip to main content

Crate bext_php

Crate bext_php 

Source
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

  1. build.rs compiles sapi/bext_php_sapi.c and links against libphp (PHP compiled with --enable-embed --enable-zts).

  2. The C SAPI implements PHP’s sapi_module_struct callbacks, forwarding all I/O (output writes, POST reads, cookies, headers) to Rust via extern "C" functions defined in ffi.rs.

  3. PhpPool manages N OS threads, each registered with PHP’s TSRM. Requests are dispatched via bounded channels (same as JscRenderPool).

  4. PhpState is the top-level handle added to bext-server’s AppState. It manages initialization, pool lifecycle, and graceful shutdown.

§Requirements

  • PHP 8.2+ compiled with --enable-embed --enable-zts
  • php-config in PATH (or set BEXT_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.