Expand description
§speedyspec-php
Embedded, statically linked PHP interpreter for speedyspec.
Part of the SpeedySpec platform.
Role: platform. Seam: container.
§What it gives you
Php::boot: starts the embedded interpreter once per process, with the hook registry and native areas inBootOptions.Php::eval,Php::call,Php::requireandPhp::serve: run code, call callables, load files and serve aWebRequest.NativeArea: a set of native functions and classes, with request start and end hooks.DOCS_RS:build.rslinks nothing when it is set, so docs.rs builds the docs without a PHP.
§Install
cargo add speedyspec-php§Requirements
A static PHP built by scripts/build-php.sh at speedyspec-php’s pinned php-version, with SPEEDYSPEC_PHP_PREFIX, PHP, PHP_CONFIG and SODIUM_LIB_DIR set. Rust 1.99.
§Features
embed(on by default) links the embedded PHP. It is required to run PHP; without it,Php::bootreturns an error. It is off only for docs.rs builds, whose ext-php-rs bindings cannot build it.
§Example
Boot PHP and evaluate an expression.
use std::rc::Rc;
use speedyspec_hooks::Value;
use speedyspec_hooks_memory::MemoryHooks;
use speedyspec_php::{BootOptions, Php};
let php = Php::boot(BootOptions { hooks: Rc::new(MemoryHooks::new()), preload: &[], areas: vec![] })
.expect("PHP boots");
assert_eq!(php.eval("example", "return 6 * 7;").unwrap(), Value::Int(42));§Where it fits
Every crate that runs PHP builds on this one: speedyspec-php-ext for the extension’s shared parts,
speedyspec-container-php and speedyspec-wp-hooks-php for their areas, and the runtime itself. The pinned PHP
version ships in the package as php-version, and a consumer’s build-php.sh reads it from the package it
resolved.
§Versioning
SemVer, 0.x: a minor version may break the API. MSRV is Rust 1.99. SpeedySpec’s own version (ADR-028) is the PHP runtime’s major, not this crate’s.
§License
MIT
§In detail
Embedded, statically linked PHP for speedyspec.
Php::boot starts the interpreter once per process. PHP is
process-global and non-thread-safe, so a Php stays on the thread that
booted it. The hook registry passed in BootOptions is exposed to PHP as
SpeedySpec\Hooks\Hook and the WordPress-named functions.
Re-exports§
pub use ext_php_rs;
Modules§
Structs§
- Boot
Options - What
Php::bootneeds. - Call
Failure - A PHP call that failed: the error, and the thrown object when PHP threw one (a
Value::Opaque), so a native function can rethrow the original exception. - Callable
- A PHP callable held by Rust, called through Zend’s fast path. See the module docs.
- Php
- A booted PHP engine with one request open.
- Served
- What serving one web request came to.
Enums§
- Output
- Where PHP’s output (
echo, error display, …) is written. - PhpError
- Why PHP could not boot or run something.
Constants§
- PHP_
VERSION - The PHP version linked into this binary: the one pinned in this crate’s
php-versionfile, which the build refuses to link anything else than.
Traits§
- Native
Area - One area of the extension.
- WebRequest
- One HTTP request, as PHP sees it.
Functions§
- call
- Calls a PHP callable from anywhere on the thread that booted PHP while a request is open, as
Php::calldoes (an adapter of a port holds noPhphandle). Fails without touching PHP when no request is open. - call_
catching - As
call, keeping the exception object a failed call threw. - eval
- Runs PHP statements (no
<?phptag) from anywhere on the thread that booted PHP while a request is open, asPhp::evaldoes (a native area holds noPhphandle). Fails without touching PHP when no request is open. - execution_
context - Identifies the execution context PHP is running in now: the main context or one fiber
(the address of its
zend_fiber_context,EG(current_fiber_context)), 0 when PHP is not running. Within one context calls nest strictly, also while other contexts are suspended mid-call, so per-context bookkeeping that is saved and restored around a call stays correct when a fiber suspends inside it. An address can be reused by a later fiber once its context is destroyed. - global
$GLOBALS[$name], through references;Nonewhen it is not set or no request is open. Runs no PHP code.- global_
array_ contains array_key_exists( $key, $GLOBALS[$name] ).- global_
array_ get $GLOBALS[$name][$key], converted to aValue;Nonewhen absent. Only that entry is converted.- global_
array_ keys - The keys of the array in
$GLOBALS[$name], in PHP’s order, as bytes (integer keys in decimal);Nonewhen the global is unset or not an array. - global_
pop array_pop($GLOBALS[$name]), in place, as WordPress pops$wp_current_filter: one entry into PHP. False (nothing done) when the global is not an array.- global_
push $GLOBALS[$name][] = $value, in place, as WordPress pushes$wp_current_filter: one entry into PHP. False (nothing done) when the global is not an array.- object_
id spl_object_id($value)for a PHP object held as aValue::Opaque.- set_
global $GLOBALS[$name] = $value: a variable referencing the global sees the new value too.- set_ini
- INI settings for every request of this process, as php.ini would give them (so
PHP_INI_PERDIRandPHP_INI_SYSTEMsettings such asupload_max_filesizeapply, whichini_set()cannot change). Call beforePhp::boot, once. A key or value with a quote, a newline or a NUL is refused.