Skip to content

Commit 8fb7e11

Browse files
committed
docs: address Copilot review on internals.md
- Add the missing BootRequested, Rebooting and RebootReady states to the lifecycle diagram and table, and reference internal/state/state.go for the full set. - Correct the environment-sandboxing description: $_SERVER is built from a copy of main_thread_env plus request-specific variables, $_ENV is populated from the same snapshot via php_import_environment_variables, and sandboxed_env is reset after each script execution (lazy re-init on next getenv/putenv). Signed-off-by: Kévin Dunglas <kevin@dunglas.fr>
1 parent 40b406c commit 8fb7e11

1 file changed

Lines changed: 17 additions & 10 deletions

File tree

docs/internals.md

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -55,25 +55,32 @@ Each thread has a `ThreadState` (defined in `internal/state/state.go`) that gove
5555
### States
5656

5757
```text
58-
Lifecycle: Reserved → Booting → Inactive → Ready ⇄ (processing)
59-
60-
Shutdown: ShuttingDown → Done → Reserved
61-
62-
Restart: Restarting → Yielding → Ready
63-
64-
Handler transition: TransitionRequested → TransitionInProgress → TransitionComplete
58+
Lifecycle: Reserved → BootRequested → Booting → Inactive → Ready ⇄ (processing)
59+
60+
Shutdown: ShuttingDown → Done → Reserved
61+
62+
Restart (admin/watcher): Restarting → Yielding → Ready
63+
64+
ZTS reboot (max_requests): Rebooting → RebootReady → Ready
65+
66+
Handler transition: TransitionRequested → TransitionInProgress → TransitionComplete
6567
```
6668

69+
The full set of states is defined in `internal/state/state.go`:
70+
6771
| State | Description |
6872
| ---------------------- | ------------------------------------------------------------------------------------ |
6973
| `Reserved` | Thread slot allocated but not booted. Can be booted on demand. |
74+
| `BootRequested` | Boot has been queued (e.g., by the main thread) but the POSIX thread hasn't started. |
7075
| `Booting` | Underlying POSIX thread is starting up. |
7176
| `Inactive` | Thread is alive but has no handler assigned. Minimal memory footprint. |
7277
| `Ready` | Thread has a handler and is ready to accept work. |
7378
| `ShuttingDown` | Thread is shutting down. |
7479
| `Done` | Thread has completely shut down. Transitions back to `Reserved` for potential reuse. |
7580
| `Restarting` | Worker thread is being restarted (e.g., via admin API or file watcher). |
7681
| `Yielding` | Worker thread has yielded control and is waiting to be re-activated. |
82+
| `Rebooting` | Worker thread is exiting the C loop for a full ZTS restart (e.g., `max_requests`). |
83+
| `RebootReady` | The C thread has exited and ZTS state is cleaned up, ready to spawn a new C thread. |
7784
| `TransitionRequested` | A handler change has been requested from the Go side. |
7885
| `TransitionInProgress` | The C thread has acknowledged the transition request. |
7986
| `TransitionComplete` | The Go side has installed the new handler. |
@@ -213,9 +220,9 @@ A separate goroutine (`startDownScalingThreads`) periodically checks (every 5s)
213220
FrankenPHP sandboxes environment variables per-thread:
214221

215222
1. At startup, the main thread snapshots `os.Environ()` into `main_thread_env` (a PHP `HashTable`)
216-
2. Each request copies `main_thread_env` into `$_SERVER`
217-
3. `frankenphp_putenv()` / `frankenphp_getenv()` use a thread-local `sandboxed_env` copy, preventing race conditions on the global environment
218-
4. The sandboxed environment is reset between requests via `reset_sandboxed_environment()`
223+
2. For each request, `$_SERVER` is built from a copy of `main_thread_env` plus request-specific variables (in `frankenphp_register_server_vars`); `$_ENV` is populated from the same snapshot through PHP's `php_import_environment_variables` hook
224+
3. `frankenphp_putenv()` / `frankenphp_getenv()` operate on a thread-local `sandboxed_env` initialized lazily from `main_thread_env`, preventing race conditions on the global C environment
225+
4. After each script execution, `reset_sandboxed_environment()` releases `sandboxed_env`; the next call re-initializes it from `main_thread_env`
219226

220227
## Request Flow (Regular Mode)
221228

0 commit comments

Comments
 (0)