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 runtime;
22mod sapi;
23mod web;
24
25pub use area::NativeArea;
26pub use callable::Callable;
27/// ext-php-rs, for areas building their functions and classes.
28pub use ext_php_rs;
29pub use global_array::{global_array_contains, global_array_get, global_array_keys};
30pub use runtime::{
31 BootOptions, CallFailure, Output, Php, PhpError, Served, call, call_catching, eval, global,
32 global_pop, global_push, object_id, set_global, set_ini,
33};
34pub use web::WebRequest;
35
36/// The PHP version linked into this binary: the one pinned in this crate's
37/// `php-version` file, which the build refuses to link anything else than.
38pub const PHP_VERSION: &str = env!("SPEEDYSPEC_PHP_VERSION");
39
40/// Identifies the execution context PHP is running in now: the main context or one fiber
41/// (the address of its `zend_fiber_context`, `EG(current_fiber_context)`), 0 when PHP is not
42/// running. Within one context calls nest strictly, also while other contexts are suspended
43/// mid-call, so per-context bookkeeping that is saved and restored around a call stays correct
44/// when a fiber suspends inside it. An address can be reused by a later fiber once its context
45/// is destroyed.
46pub fn execution_context() -> usize {
47 boundary::execution_context()
48}
49
50/// How many times this process has entered the PHP engine. Every entry the
51/// bridge makes (running code, calling a callable, firing a PHP callback,
52/// releasing a PHP value) is counted; tests use it to show when PHP was not
53/// entered at all.
54#[doc(hidden)]
55pub fn php_entries() -> u64 {
56 boundary::entries()
57}
58
59/// How many saved per-context records the fiber bookkeeping holds (contexts
60/// not running now, abandoned fibers included); tests use it to see records
61/// created, freed and forgotten.
62#[doc(hidden)]
63pub fn fiber_records() -> usize {
64 boundary::fiber_records()
65}