Skip to content

feat: frankenphp_get_vars() and WorkerHandle::setVars() - #2635

Open
nicolas-grekas wants to merge 2 commits into
php:mainfrom
nicolas-grekas:bgworker-vars
Open

nicolas-grekas wants to merge 2 commits into
php:mainfrom
nicolas-grekas:bgworker-vars

Conversation

@nicolas-grekas

@nicolas-grekas nicolas-grekas commented Sep 6, 2026 •

Copy link
Copy Markdown
Contributor

Stacked on #2617: review the last commit.

Shared state for background workers, the vars half of #2287. A worker declares the namespaces it publishes, and readers name the namespace, never the worker:

worker {
	file config.php
	background
	vars redis feature_flags
}
// the background worker, before its first tick()
$handle->setVars('redis', ['dsn' => 'redis://cache:6379']);

// anywhere
$redis = frankenphp_get_vars('redis');
  1. A namespace has one publisher per scope, the reader's php_server first, then the global workers, and Validate() refuses conflicts; a worker publishing vars runs a single thread. Between two requests, a worker script reads as the request before it did.
  2. Every declared namespace is published before the first tick(), which the server start waits for, so requests never wait for a snapshot.
  3. Snapshots belong to the worker, not to a run: a restarting worker keeps serving its last ones. They own their memory, so a reboot of the engine can't leave them dangling.
  4. Values are null, scalars, arrays or enums, and references in arrays are followed. A snapshot that doesn't fit in what is left of the reader's memory_limit throws instead of being copied.

Left out on purpose: the unchanged-data skip of #2287, until there are numbers for it. The per-request cache is #2827.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant