Skip to main content

PhpConfig

Struct PhpConfig 

Source
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: bool

Enable the PHP runtime. Default: false.

§document_root: String

Document 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: String

Index file name for directory requests. Default: “index.php”

§max_body_bytes: usize

Maximum request body size in bytes. Default: 8MB.

§max_execution_time: u32

Maximum execution time per request in seconds. Default: 30.

§cache_responses: bool

Enable 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: u64

Worker 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

Source

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.

Source

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.

Source

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.

Source

pub fn is_php_request(&self, path: &str) -> bool

Check whether a request path should be handled by PHP.

Source

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.

Trait Implementations§

Source§

impl Debug for PhpConfig

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for PhpConfig

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for PhpConfig

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,