Skip to main content

Worker options

Zeridion\Flare\Worker\WorkerOptions configures a worker. Construct it directly with named arguments, or build it from the environment with WorkerOptions::fromEnv().

use Zeridion\Flare\Worker\WorkerOptions;

$options = new WorkerOptions(
apiKey: 'zf_live_sk_...',
baseUrl: 'https://api.zeridion.com',
queues: ['default', 'email'],
pollIntervalSeconds: 2.0,
);

$worker = new FlareWorker($options);

From the environment

$options = WorkerOptions::fromEnv();

reads these environment variables:

VariableMaps toDefault
FLARE_API_KEYapiKey— (falls back to the env var when apiKey is null)
FLARE_BASE_URLbaseUrlhttps://api.zeridion.com
FLARE_QUEUESqueues (comma-separated)default
FLARE_POLL_INTERVALpollIntervalSeconds2.0

Pass overrides as the first argument to layer explicit values on top:

$options = WorkerOptions::fromEnv(['concurrency' => 5]);

All options

OptionTypeDefaultDescription
apiKey?stringnullAPI key. Falls back to FLARE_API_KEY.
baseUrlstringhttps://api.zeridion.comAPI base URL.
queuesstring[]['default']Queues this worker serves.
concurrencyint1In-flight job cap. One job per process — values above 1 log a warning.
pollIntervalSecondsfloat2.0Idle delay between empty polls.
defaultTimeoutSecondsint1800Fallback per-job timeout when a job omits one.
defaultMaxAttemptsint3Fallback maximum attempts.
pollRequestTimeoutSecondsfloat35.0Read timeout for the long-poll. Kept above 30 s so it never races the long-poll.
shutdownGraceSecondsfloat30.0Time allowed to finish the in-flight job on shutdown.
maxJobsPerProcessint0Exit after this many jobs so a supervisor restarts a fresh process (0 = never).
maxMemoryMbint0Exit when memory exceeds this many MiB (0 = never).
loggerLoggersilentWhere the worker writes structured logs. Defaults to a silent sink.

Logging

By default the worker logs nothing. Supply a logger to see lifecycle and per-job events:

use Zeridion\Flare\Worker\StderrLogger;

$options = new WorkerOptions(apiKey: '...', logger: new StderrLogger('info'));

StderrLogger writes one line per event to standard error. To route worker logs through your own logging stack, implement Zeridion\Flare\Worker\Logger (a small log(level, message, context) contract that mirrors the standard log levels).

Process recycling

Long-lived PHP processes can accumulate memory. Set maxJobsPerProcess or maxMemoryMb so the worker exits cleanly after a threshold; a process supervisor then starts a fresh one.

See also