Skip to main content
The SDK keeps every config, secret, and flag in an in-memory array that is replaced atomically on each sync. Read methods never block the network after the first sync.

When does the SDK hit the network

PHP-FPM per-request model

In PHP-FPM, each HTTP request boots a fresh PHP process. The in-memory cache is empty at the start of every request and NexusClient::create makes a blocking network call on every request. The TTL has no effect across requests because there is no shared memory.Recommendation: register the client in a DI container with request scope (the default in Symfony/Laravel) so the cache is built once per request and all service classes share it within that request.
For long-running processes (CLI daemons, Swoole workers, ReactPHP servers), the cache persists across multiple reads as expected and the TTL controls background refresh frequency.

ETag / 304 protocol

Every successful sync stores the server’s ETag header. The next sync sends If-None-Match: <etag>. If nothing has changed:
The SDK resets its internal TTL timestamp and serves the existing cache. No payload is transferred. When the ETag changes, the new payload replaces the cache atomically.

Background sync errors

Background TTL syncs never throw exceptions to the caller. If the network call fails:
  1. The error is logged via the configured PSR-3 logger at the error level.
  2. The existing cache continues to be served.
  3. The next read after the TTL elapses retries automatically.
The application is never notified - a transient backend blip does not surface as a customer-facing error.

Error-never-clears-cache rule

The SDK never empties the cache on a sync failure. Even a NexusBillingException or NexusRateLimitedException leaves the last-known-good snapshot intact. This is intentional: it is safer to serve potentially stale config values than to serve nothing.

Cache lifetime

The cache lives for the lifetime of the NexusClient object.
  • FPM/HTTP workers - cache lives for one request (PHP process is recycled after the response).
  • CLI daemons / queue workers - cache lives for the lifetime of the process.
Share the client instance rather than constructing one per call:

File-type secrets

Secrets with type = 'file' are materialised to a temp file on every sync:
The hash prefix is derived from the secret value, so the path changes whenever the value changes and the old file is removed automatically. Files are written with mode 0600. Temp files are deleted when the NexusClient object is garbage-collected (__destruct). In FPM, this happens at the end of each request.

Diagnostics

Enable debug-level logging in your PSR-3 logger to see one line per sync:
See Custom logging for how to wire up a logger.