pub struct PhpConfig {
pub enabled: bool,
pub document_root: String,
pub workers: Option<usize>,
pub ini: HashMap<String, String>,
pub extensions: Vec<String>,
pub index: String,
pub max_body_bytes: usize,
pub max_execution_time: u32,
pub cache_responses: bool,
pub max_requests: u64,
pub worker_script: Option<String>,
}Expand description
Configuration for the embedded PHP runtime.
Fields§
§enabled: boolEnable the PHP runtime. Default: false.
document_root: StringDocument root for PHP scripts. Requests are resolved relative to this. Default: “./public”
workers: Option<usize>Number of PHP worker threads. Default: number of CPU cores. Each thread holds a PHP TSRM context and processes one request at a time.
ini: HashMap<String, String>PHP INI overrides (key=value pairs).
Example:
[php.ini]
display_errors = "Off"
memory_limit = "256M"
opcache.enable = "1"extensions: Vec<String>File extensions to treat as PHP scripts. Default: [“.php”]
index: StringIndex file name for directory requests. Default: “index.php”
max_body_bytes: usizeMaximum request body size in bytes. Default: 8MB.
max_execution_time: u32Maximum execution time per request in seconds. Default: 30.
cache_responses: boolEnable ISR caching for PHP responses. Default: true. GET requests with 200 status are cached using the ISR cache with tag-based invalidation. POST/PUT/DELETE requests bypass the cache. Use route_rules to control TTL per path pattern.
max_requests: u64Worker lifecycle: rotate after this many requests. Default: 10000. Helps contain memory leaks in PHP extensions.
worker_script: Option<String>Worker mode: path to the worker PHP script.
When set, bext-php boots this script once per thread and dispatches
requests to its bext_handle_request($callback) loop.
Eliminates per-request framework bootstrap (~3ms for Laravel).
Example worker script:
$app = require __DIR__.'/../bootstrap/app.php';
$kernel = $app->make(\Illuminate\Contracts\Http\Kernel::class);
while (bext_handle_request(function() use ($kernel) {
$response = $kernel->handle($request = \Illuminate\Http\Request::capture());
$response->send();
$kernel->terminate($request, $response);
})) { gc_collect_cycles(); }Implementations§
Source§impl PhpConfig
impl PhpConfig
Sourcepub fn effective_workers(&self) -> usize
pub fn effective_workers(&self) -> usize
Effective worker count (configured or CPU count).
NTS (non-thread-safe) PHP is limited to 1 worker because the PHP interpreter uses global state without TSRM protection. ZTS builds can use multiple workers safely.
Sourcepub fn ini_entries_string(&self) -> String
pub fn ini_entries_string(&self) -> String
Build the INI entries string for bext_php_module_init.
Applies sensible production defaults for OPcache/JIT when not
explicitly overridden by the user.
Sourcepub fn is_worker_mode(&self) -> bool
pub fn is_worker_mode(&self) -> bool
Whether worker mode is configured and available. Worker mode requires ZTS PHP — NTS PHP can only run classic mode because the PHP interpreter uses process-global state that isn’t safe to access from spawned threads in worker mode.
Sourcepub fn is_php_request(&self, path: &str) -> bool
pub fn is_php_request(&self, path: &str) -> bool
Check whether a request path should be handled by PHP.
Sourcepub fn resolve_script(&self, request_path: &str) -> Option<String>
pub fn resolve_script(&self, request_path: &str) -> Option<String>
Resolve a request path to a filesystem path.
Returns the absolute script path if the file exists, or None.