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
get_vars is now pure-read; the lazy-start lives in
require_background_worker. Updated the How It Works steps, the
named/catch-all bullets in Configuration, and the Caddyfile comment
that described the catch-all as "handles any unlisted name via
get_vars()".
Copy file name to clipboardExpand all lines: docs/background-workers.md
+6-6Lines changed: 6 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,8 +7,8 @@ They observe their environment and publish variables that HTTP threads (both [wo
7
7
8
8
1. A background worker runs its own event loop (subscribe to Redis, watch files, poll an API...)
9
9
2. It calls `frankenphp_set_vars()` to publish a snapshot of key-value pairs
10
-
3. HTTP threads call `frankenphp_get_vars()` to read the latest snapshot
11
-
4.The first `get_vars()`call blocks until the background worker has published - no startup race condition
10
+
3. HTTP threads call `frankenphp_require_background_worker()` to declare a dependency and ensure the worker is running (lazy-started if needed, blocks until it has published at least once)
11
+
4.HTTP threads then call `frankenphp_get_vars()`to read the latest snapshot (pure read, no blocking)
12
12
13
13
## Configuration
14
14
@@ -27,16 +27,16 @@ example.com {
27
27
name feature-flags
28
28
}
29
29
30
-
# Catch-all - handles any unlisted name via get_vars()
30
+
# Catch-all - handles any unlisted name via require_background_worker()
31
31
worker /app/bin/console {
32
32
background
33
33
}
34
34
}
35
35
}
36
36
```
37
37
38
-
-**Named** (with `name`): lazy-started on first `get_vars()` call, or auto-started at boot if `num 1` is set.
39
-
-**Catch-all** (no `name`): also lazy-started. Use `max_threads` to cap how many can be created (defaults to 16). Not declaring a catch-all forbids unlisted names.
38
+
-**Named** (with `name`): lazy-started on first `require_background_worker()` call, or auto-started at boot if `num 1` is set.
39
+
-**Catch-all** (no `name`): lazy-started on demand too, for any name not matched by a `name` directive. Use `max_threads` to cap how many can be created (defaults to 16). Not declaring a catch-all forbids unlisted names.
40
40
- Each `php_server` block has its own isolated scope - two blocks can use the same worker names without conflict.
41
41
-`max_consecutive_failures`, `env`, and `watch` work the same as HTTP workers.
42
42
@@ -241,5 +241,5 @@ if (function_exists('frankenphp_get_vars')) {
241
241
-`$_SERVER['FRANKENPHP_WORKER_NAME']` is set for all workers (HTTP and background)
242
242
-`$_SERVER['FRANKENPHP_WORKER_BACKGROUND']` is `true` for background workers, `false` for HTTP workers
243
243
-`$_SERVER['argv']` = `[entrypoint, name]` in background workers (for `bin/console` compatibility)
244
-
- Crash recovery with automatic restart and exponential backoff. During the restart window, `get_vars` returns the last published data (stale but available). A warning is logged on crash (`background worker exited, restarting`).
244
+
- Crash recovery with automatic restart and exponential backoff. During the restart window, `get_vars()` returns the last published data (stale but available) since the vars stay in persistent memory across crashes. A warning is logged on crash (`background worker exited, restarting`).
245
245
- On shutdown/restart: the signaling stream is closed (EOF). Workers have 5 seconds to exit. Stuck workers are force-killed on Linux and Windows.
0 commit comments