You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: grace period and force-kill for background worker shutdown
On restart/shutdown, background workers receive "stop\n" on the
signaling stream and have 5 seconds to exit gracefully.
After the grace period, stuck threads get a best-effort force-kill
by arming PHP's own max_execution_time timer cross-thread (Linux ZTS
only, via timer_settime on EG(max_execution_timer_timer)). This
triggers a "Maximum execution time exceeded" fatal error on the
stuck thread. On other platforms, stuck threads are abandoned and
exit when the blocking call eventually returns.
Copy file name to clipboardExpand all lines: docs/background-workers.md
+5-4Lines changed: 5 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -36,15 +36,15 @@ example.com {
36
36
37
37
-`num` and `max_threads` are accepted but capped at 1 for now (pooling is a future feature). Values > 1 are rejected with a clear error.
38
38
-`max_threads` on catch-all workers sets a safety cap for lazy-started instances (defaults to 16).
39
-
-`max_consecutive_failures` defaults to -1 (never panic on boot failures).
39
+
-`max_consecutive_failures` defaults to 6 (same as HTTP workers).
40
40
-`env` and `watch` work the same as HTTP workers.
41
41
42
42
### Thread reservation
43
43
44
44
Background workers get dedicated thread slots outside the global `max_threads` budget.
45
45
They don't compete with HTTP auto-scaling. For catch-all workers, `max_threads` determines
46
-
the reservation (default 16). Named workers with `num 0` (default) are lazy-started and
47
-
don't reserve threads.
46
+
the reservation (default 16). Named workers with `num 0` (default) are lazy-started but
47
+
still reserve 1 thread (`max_threads` defaults to `max(num, 1)`).
48
48
49
49
Each `php_server` block has its own isolated background worker scope.
50
50
@@ -199,7 +199,8 @@ if (function_exists('frankenphp_worker_get_vars')) {
199
199
- Background workers also get `$_SERVER['argv']` = `[entrypoint, name]` for CLI compatibility
200
200
- Crash recovery: automatic restart with exponential backoff
201
201
- Graceful shutdown via `frankenphp_worker_get_signaling_stream()` and `stream_select()`
202
-
- Worker restarts stop running background workers; the next `get_vars()` call starts them again
202
+
- Grace period: on restart/shutdown, background workers receive `"stop\n"` on the signaling stream and have 5 seconds to exit gracefully. Workers still blocked after 5 seconds are abandoned (their threads exit when the blocking call returns).
203
+
- Worker restarts stop and immediately restart background workers (same as HTTP workers)
203
204
- Use `error_log()` or `frankenphp_log()` for logging - avoid `echo`
204
205
205
206
For advanced use cases (amphp, ReactPHP), the signaling stream can be registered directly
0 commit comments