speedyspec_php/lib.rs
1#![doc = include_str!("../README.md")]
2// Without `embed` (docs.rs only) nothing can boot PHP, so the code only the engine reaches is unused there.
3#![cfg_attr(not(feature = "embed"), allow(dead_code, unused_imports))]
4//!
5//! ## In detail
6//!
7//! Embedded, statically linked PHP for speedyspec.
8//!
9//! [`Php::boot`] starts the interpreter once per process. PHP is
10//! process-global and non-thread-safe, so a [`Php`] stays on the thread that
11//! booted it. The hook registry passed in [`BootOptions`] is exposed to PHP as
12//! `SpeedySpec\Hooks\Hook` and the WordPress-named functions.
13
14mod area;
15mod boundary;
16mod callable;
17mod convert;
18mod global_array;
19mod hook_class;
20pub mod native;
21mod reference;
22mod runtime;
23mod sapi;
24mod web;
25
26pub use area::NativeArea;
27pub use callable::Callable;
28/// ext-php-rs, for areas building their functions and classes.
29pub use ext_php_rs;
30pub use global_array::{global_array_contains, global_array_get, global_array_keys};
31pub use runtime::{
32 BootOptions, CallFailure, Output, Php, PhpError, Served, call, call_catching, eval, global,
33 global_pop, global_push, object_id, set_global, set_ini,
34};
35pub use web::WebRequest;
36
37/// The PHP version linked into this binary: the one pinned in this crate's
38/// `php-version` file, which the build refuses to link anything else than.
39pub const PHP_VERSION: &str = env!("SPEEDYSPEC_PHP_VERSION");
40
41/// Identifies the execution context PHP is running in now: the main context or one fiber
42/// (the address of its `zend_fiber_context`, `EG(current_fiber_context)`), 0 when PHP is not
43/// running. Within one context calls nest strictly, also while other contexts are suspended
44/// mid-call, so per-context bookkeeping that is saved and restored around a call stays correct
45/// when a fiber suspends inside it. An address can be reused by a later fiber once its context
46/// is destroyed.
47pub fn execution_context() -> usize {
48 boundary::execution_context()
49}
50
51/// How many times this process has entered the PHP engine. Every entry the
52/// bridge makes (running code, calling a callable, firing a PHP callback,
53/// releasing a PHP value) is counted; tests use it to show when PHP was not
54/// entered at all.
55#[doc(hidden)]
56pub fn php_entries() -> u64 {
57 boundary::entries()
58}
59
60/// How many saved per-context records the fiber bookkeeping holds (contexts
61/// not running now, abandoned fibers included); tests use it to see records
62/// created, freed and forgotten.
63#[doc(hidden)]
64pub fn fiber_records() -> usize {
65 boundary::fiber_records()
66}