feat: name Server instances and attribute workers to them#2529
Merged
AlliBalliBaba merged 4 commits intoJul 20, 2026
Conversation
The name is a human-readable identifier passed to NewServer(); when empty it defaults to the index the server gets at registration time. It allows attributing workers, metrics and logs to a specific server.
The name is resolved when registering the module: first host of the enclosing route's host matcher, else the first listener address of the http server containing the module.
Two php_server blocks declaring a worker with the same name (or same
default file name) used to get an order-dependent numeric postfix
("queue", "queue_1"), making metrics attribution ambiguous. The
colliding name is now qualified with the resolved server name
("two.example.com:queue") before falling back to the postfix.
nicolas-grekas
force-pushed
the
server-name
branch
from
July 19, 2026 16:48
ebac7dc to
b02fb72
Compare
Contributor
|
If determining the server name like this is reliable then this looks fine to me 👍 Since a route can potentially contain multiple php_server{
name "my-server"
} |
Signed-off-by: Alexander Stecher <45872305+AlliBalliBaba@users.noreply.github.com>
AlliBalliBaba
pushed a commit
that referenced
this pull request
Jul 20, 2026
Follow-up to #2499, targeting `refactor/phpserver`. Docs-only. The refactor introduces new public API for library users (`NewServer`, `WithServer`, `Server.ServeHTTP`, `WithWorkerServerScope`, `WithWorkerMatcher`) with no documentation outside godoc. This adds a `docs/library.md` page covering: - minimal setup: `NewServer` + `Init(WithServer(...))` + `Server.ServeHTTP` as an `http.Handler` - registering multiple servers (the library equivalent of multiple `php_server` blocks) - scoping workers to a server, by path and by request matcher - per-request options - the compatibility path: package-level `ServeHTTP()` keeps working through the fallback server Also linked from the README docs list and `llms.txt`. The examples follow the current `NewServer` signature on the branch; if #2529 lands first, the snippets need a one-line update (happy to rebase either way). Translations are left to the usual translation update flow.
This was referenced Jul 20, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to the discussion in #2499 (#2499 (comment)): this adds an optional human-readable name to
Server, targeting therefactor/phpserverbranch.Three commits, each independently buildable:
NewServer()takes anameas first argument. When empty, it defaults to the server index at registration time. AServer.Name()getter is exposed; the field stays private.php_serverblock when registering the module. Cascade: first host of the enclosing route's host matcher (e.g.api.example.com), else the first listener address of the http server containing the module. Reuses the*caddyhttp.Appalready fetched inProvision().createUniqueWorkerName()qualifies colliding worker names with the server name before falling back to the numeric postfix. Two blocks each declaring aqueueworker now yieldqueueandtwo.example.com:queueinstead ofqueueandqueue_1, so metrics stay attributable. Non-colliding names are unchanged (no BC impact on metric labels).The last commit is separable if you'd rather keep the naming behavior untouched for now; the first two are what #2398 needs to reuse
Serveras the scope for background workers without a parallel label registry.Not included on purpose: enforcing name uniqueness across servers (the index remains the identity), and any change to
NewServer's signature style. If you'd prefer variadicServerOptions over the growing positional list, I'm happy to adapt.