diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-07-02 05:12:39 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-07-02 05:12:39 +0900 |
| commit | 7fd7df848cdbbd8792b0043799018d51408458fc (patch) | |
| tree | 28aeeef87c3d86a662ed1328b53b1a2865df2c6d /docs | |
| parent | eab3a31c5750013c53c0eb02adc976d6757dc9f7 (diff) | |
| download | php-shirabe-7fd7df848cdbbd8792b0043799018d51408458fc.tar.gz php-shirabe-7fd7df848cdbbd8792b0043799018d51408458fc.tar.zst php-shirabe-7fd7df848cdbbd8792b0043799018d51408458fc.zip | |
feat(php-rpc): implement Runtime::has_constant/get_constant via php-rpc
Runtime::hasConstant/getConstant need a real PHP interpreter's defined()/
constant() to answer platform requirement checks (e.g. PHP_ZTS, PHP_INT_SIZE),
which the shim can't provide since Rust constants aren't queryable by string.
Extend shirabe-php-rpc's protocol to carry one string argument and return the
full PHP scalar range, add defined/constant dispatch entries to the worker,
and wire Runtime and get_php_version/get_php_binary onto them.
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/dev/php-rpc.md | 33 |
1 files changed, 19 insertions, 14 deletions
diff --git a/docs/dev/php-rpc.md b/docs/dev/php-rpc.md index 9fc6ca3..ad5d3f1 100644 --- a/docs/dev/php-rpc.md +++ b/docs/dev/php-rpc.md @@ -10,10 +10,11 @@ system PHP as a child process and asks it for runtime information over a Unix do The crate supports exactly one interaction pattern, and nothing else: -> Rust calls a named, argument-less PHP function and receives a single fixed-type scalar back. +> Rust calls a named PHP function, passing a single string argument, and receives a single scalar +> back. - Rust to PHP only. PHP never calls back into Rust. -- No arguments. +- Exactly one argument, and it must be a string. - Scalar return values only (string / int / float / bool / null). - Every failure is ignored: a PHP exception, serialization/deserialization failure, a missing PHP function, a crashed child, etc. None are handled. @@ -29,32 +30,36 @@ Reuse the existing `PhpExecutableFinder` class to resolve the PHP binary. - A Unix domain socket. (No Windows support for now) - The PHP glue code is a small script written to a temporary file. - Message frame: `[usize length (little-endian)][payload]`. - - Request payload: the bare PHP function name as raw bytes. - - Response payload: `serialize()` of the function's return value. + - Request payload: the PHP function name as raw bytes, followed by a `\0` byte and the string + argument (function names are static literals and never contain `\0`, so the first `\0` + unambiguously separates name from argument). + - Response payload: `serialize()` of the function's return value — any of `N;` (null), `b:0/1;` + (bool), `i:<n>;` (int), `d:<f>;` (float), or `s:<len>:"<bytes>";` (string). -The PHP worker is a single read-eval-respond loop: read a framed function name, -call the matching entry in a fixed dispatch table, send back `serialize($result)`. +The PHP worker is a single read-eval-respond loop: read a framed function name and argument, call +the matching entry in a fixed dispatch table (`defined`, `constant`), send back +`serialize($result)`. ## Global state and public API PHP runtime information (e.g., process handle) is held as process-global state rather than threaded through call sites for now. -The crate exposes plain free functions: +The crate exposes plain free functions. For example: -```rust -shirabe_php_rpc::get_php_version() -> String -``` +* get_php_version() +* has_constant() +* get_constant() The connection is a process-global `static` (e.g. `OnceLock<Mutex<Worker>>`), lazily initialized on -the first call: the first `get_php_version()` spawns the child, performs the handshake, and caches -the connection. Commands that never query PHP never start it. The child lives for the rest of the -process and is left to be reaped at exit (no explicit shutdown message). +the first call: the first call spawns the child, performs the handshake, and caches the connection. +Commands that never query PHP never start it. The child lives for the rest of the process and is +left to be reaped at exit (no explicit shutdown message). A future revision threads this runtime information through arguments or embeds it in structs; for now callers just reach for the global getter. ## Out of scope -Deferred things: arguments and non-scalar return values, PHP to Rust callbacks +Deferred things: multiple/non-string arguments, non-scalar return values, PHP to Rust callbacks and re-entrancy, object handles / proxies / identity, stub generation, error propagation, GC / lifecycle, and Windows support. |
