Skip to content

Commit 678e56e

Browse files
committed
docs: address review feedback
- Soften the $_ENV note: state the current behavior without claiming a performance rationale. - Simplify the state-persistence example loop. - Clarify that Symfony and Laravel Octane reset most state, but user services may need to implement Symfony's ResetInterface. - Add a `text` language to fenced state-machine and protocol diagrams in internals.md to satisfy markdownlint MD040. Signed-off-by: KΓ©vin Dunglas <kevin@dunglas.fr>
1 parent af8858c commit 678e56e

2 files changed

Lines changed: 8 additions & 8 deletions

File tree

β€Ždocs/internals.mdβ€Ž

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ Each thread has a `ThreadState` (defined in `internal/state/state.go`) that gove
5454

5555
### States
5656

57-
```
57+
```text
5858
Lifecycle: Reserved β†’ Booting β†’ Inactive β†’ Ready ⇄ (processing)
5959
↓
6060
Shutdown: ShuttingDown β†’ Done β†’ Reserved
@@ -98,7 +98,7 @@ This guarantees mutual exclusion: only one of `shutdown()`, `setHandler()`, or `
9898

9999
When a thread needs to change its handler (e.g., from inactive to worker):
100100

101-
```
101+
```text
102102
Go side (setHandler) C side (PHP thread)
103103
───────────────── ─────────────────
104104
RequestSafeStateChange(
@@ -121,7 +121,7 @@ This protocol ensures the handler pointer is never read and written concurrently
121121

122122
When workers are restarted (e.g., via admin API):
123123

124-
```
124+
```text
125125
Go side (RestartWorkers) C side (worker thread)
126126
───────────────── ─────────────────
127127
RequestSafeStateChange(

β€Ždocs/worker.mdβ€Ž

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ $handler = static function () use ($workerServer) {
170170
```
171171

172172
Most superglobals (`$_GET`, `$_POST`, `$_COOKIE`, `$_FILES`, `$_SERVER`, `$_REQUEST`) are automatically reset between requests.
173-
However, **`$_ENV` is not reset between requests** for performance reasons.
173+
However, **`$_ENV` is currently not reset between requests**.
174174
This means that any modifications made to `$_ENV` during a request will persist and be visible to subsequent requests handled by the same worker thread.
175175
Avoid storing request-specific or sensitive data in `$_ENV`.
176176

@@ -196,10 +196,10 @@ $handler = static function () {
196196
echo getCounter(); // 1, 2, 3, ... for each request on this thread
197197
};
198198

199-
for ($nbRequests = 0; ; ++$nbRequests) {
200-
if (!\frankenphp_handle_request($handler)) break;
199+
while (\frankenphp_handle_request($handler)) {
200+
// ...
201201
}
202202
```
203203

204-
When writing worker scripts, make sure to reset any request-specific state at the beginning of each request handler.
205-
Frameworks like [Symfony](symfony.md) and [Laravel Octane](laravel.md) handle this automatically.
204+
When writing worker scripts, make sure to reset any request-specific state between requests.
205+
Frameworks like [Symfony](symfony.md) and [Laravel Octane](laravel.md) take care of resetting most state for you, but you may still need to reset your own services. With Symfony, services that hold request-specific state should implement [`Symfony\Contracts\Service\ResetInterface`](https://github.com/symfony/contracts/blob/main/Service/ResetInterface.php) so they're reset by the kernel between requests.

0 commit comments

Comments
Β (0)