Skip to content

Clustering

pam start turns one PHP entry point into a supervised cluster: a master process that owns the listening sockets and a set of workers that each boot your application once and serve requests from memory. The master restarts crashed workers with backoff, recycles workers after a request budget, reloads the whole cluster without dropping connections, and exposes a health and metrics control plane that never enters PHP.

Use pam start directly under systemd, Docker or Kubernetes. When you want PAM itself to keep the cluster online, use pam up, which runs pam start under the PAM process manager.

Terminal window
pam start index.php --workers 4

The script defaults to index.php. Arguments after the script (or after --) are passed to your application:

Terminal window
pam start server.php --workers 4 -- --region=eu

The port is whatever your application passes to listen(). Every worker binds the same address with SO_REUSEPORT, so the kernel spreads new connections across them.

● READY Pam listening on http://127.0.0.1:3000 worker=1
● READY Pam listening on http://127.0.0.1:3000 worker=2
Pam master 1032739 started 2 worker(s); send SIGHUP for zero-downtime reload
Option Default Description
--workers N available CPUs HTTP worker processes (maximum 256)
--max-requests N 10000000 Recycle a worker after N requests
--task-workers N|auto 0 Extra workers that run tasks and ticks instead of public HTTP (maximum 64; auto is one per CPU)
--graceful-timeout MS 15000 How long a draining worker may take before it is killed
--startup-timeout MS 30000 How long a worker generation may take to report ready
--restart-backoff MS 100 Initial delay before restarting a crashed worker
--watchdog-grace MS 250 Extra grace before the master kills a worker stuck past its request deadline
--admin-address IP:PORT off Expose the health and metrics control plane
--php-extension NAME — Repeatable allowlist of PHP extensions to load in isolated mode (maximum 64)
--isolate-php-extensions off Isolate extensions even when the allowlist is empty
--ingress-address IP:PORT — Public address of the pool ingress (required with --pool)
--pool NAME=WORKERS@PREFIX[,PREFIX] — Route path prefixes to a dedicated worker pool (repeatable)
--state-file PATH — Write the master state as JSON (used by the process manager)

The control plane token comes from the environment, not a flag: PAM_ADMIN_TOKEN or PAM_ADMIN_TOKEN_FILE. A non-loopback --admin-address without one of them refuses to start.

Start with one worker per CPU core (the default), then tune from measurements: p95/p99 latency, RSS per worker, event-loop lag and the capacity of your database. Each worker serves many concurrent requests on Fibers, so I/O-bound applications rarely need more workers than cores. Applications that block (synchronous calls, CPU-heavy work) need more workers, PAM_IO_THREADS=1, or a process pool.

On Linux, when the cluster has at least two workers, the master starts one zygote process per generation. The zygote initializes the Zend engine and its OPcache/JIT shared memory once and forks each worker from it, like PHP-FPM children share one segment. Workers then share compiled scripts instead of keeping one copy each.

By default the fork happens before any PHP code runs (engine mode), so every worker still boots Composer and your application from pristine state. Laravel Octane on PAM boots the application in the zygote by default (app mode), so workers start serving milliseconds after the fork and share the boot’s memory copy-on-write.

Variable Effect
PAM_PREFORK=0 Disable the zygote; every worker is exec’d with its own OPcache
PAM_PREFORK_BOOT=app Fork workers from a booted application
PAM_PREFORK_BOOT=engine Fork workers from a bare engine

A zygote that cannot fork its booted state safely falls back to engine mode and logs why. Pools always fork from the engine. A SIGHUP creates a new zygote, so a new generation sees updated code even with opcache.validate_timestamps=0.

SO_REUSEPORT distributes new connections by hash, so with keep-alive clients a few workers can end up holding noticeably more connections than others, and their queues set your tail latency. Workers forked from the same zygote share a small table of connection counts: when a worker accepts a connection while holding at least two more than its least-loaded sibling, it hands the socket to that sibling over SCM_RIGHTS. This costs one message per moved connection, never per request.

Set PAM_BALANCE=0 to turn it off. TLS connections terminated by PAM are not balanced.

--max-requests is a ceiling, not an exact number. To avoid every worker recycling at the same moment, PAM lowers the effective limit of each worker by up to 25%, spread evenly across workers. Recycling is make-before-break:

  1. A worker that reaches its limit asks the master for a replacement and keeps serving.
  2. The master boots the replacement (from the same zygote) and only then sends SIGTERM to the old worker.
  3. The old worker drains: it leaves balancing, closes HTTP/1 connections after their current request, and hands its listening socket back to the master, which the replacement adopts.

Use --max-requests as a second line of defence against memory growth in third-party code; set the final value from a soak test, not from a benchmark.

When a worker exits unexpectedly, the master restarts it after --restart-backoff, doubling the delay after each consecutive failure up to 30 seconds. The failure count resets when a worker stays up for 60 seconds. A worker that exits cleanly (it was recycled on purpose) is replaced immediately.

A request stuck past requestTimeoutMs gets 504 from the worker itself, which then asks to be recycled. The master only kills a worker that failed to do so within one second plus --watchdog-grace, for example a fully hung process.

Send SIGHUP to the master to deploy new code:

Terminal window
kill -HUP <master-pid>

The master boots a complete new generation and waits for it to be ready. Only then does it activate the new generation and drain the old one. If the new generation fails readiness within --startup-timeout, the master keeps the current generation and logs:

pam: generation 2 failed readiness; keeping generation 1: ...

On success:

Pam master activated worker generation 2

SIGTERM (or SIGINT) shuts the cluster down gracefully: workers stop accepting, finish in-flight requests within --graceful-timeout, and the master exits.

Terminal window
pam start index.php --workers 2 --admin-address 127.0.0.1:3010
Endpoint Returns
GET /live The master is alive
GET /startup The first generation finished booting
GET /ready All desired workers are ready or busy
GET /metrics Prometheus text, aggregated across workers
GET /diagnostics Versioned JSON per worker, including event-loop lag
Terminal window
curl -s http://127.0.0.1:3010/metrics | grep -v '^#' | head -4
pam_cluster_ready 1
pam_cluster_workers 2
pam_http_requests_total 1
pam_http_errors_total 0

Other methods get 405; unknown paths get 404. pam top reads this endpoint and renders it live.

--task-workers N starts N extra workers that never receive public traffic. They run tasks dispatched by your application (see Background Tasks) and receive a tick once per second. They listen only on a private loopback address authenticated with a random per-server token, and they are recycled, reloaded and restarted like HTTP workers. The default is 0: without the flag there is no extra process, timer or connection.

Terminal window
pam start index.php --workers 8 --task-workers 2

Pools split one application into dedicated groups of workers by path prefix, so a slow area (reports, exports) cannot starve a fast one. A small Rust ingress listens on --ingress-address and proxies each request to the pool whose prefix matches:

Terminal window
pam start index.php \
--ingress-address 0.0.0.0:8080 \
--pool 'api=6@/api,/graphql' \
--pool 'web=2@*'

Rules:

  • --pool requires --ingress-address.
  • Exactly one pool must use the * fallback prefix.
  • Prefixes are * or absolute paths; pool names use letters, numbers, - and _.
  • The total of all pool workers replaces --workers and cannot exceed 256.
  • Each pool listens on its own private loopback port, chosen at start.

Official releases ship a broad extension set. To load only what your application needs, list the extensions explicitly:

Terminal window
pam start index.php --workers 16 --php-extension iconv --php-extension mbstring

pam extensions derives that list from your locked Composer requirements and prints the exact arguments to use (--toml prints a pam.toml profile for Declarative Deploys).

Each worker receives a few variables you can read with getenv():

Variable Value
PAM_WORKER_ID The worker’s number, starting at 1
PAM_WORKER_GENERATION The generation, incremented by each reload
PAM_WORKER_POOL The pool name, when pools are used
PAM_TASK_WORKER 1 in task workers

See Environment Variables for the complete list.