Glossary

Graceful Shutdown

Graceful shutdown is the process of stopping a service without abruptly terminating it: the service first stops accepting new requests, finishes processing active ones, and only then stops. The alternative — kill -9 — cuts connections mid-flight.

Why it matters

Unix signals

SIGTERM — a request to terminate (graceful). SIGKILL — forced termination (cannot be intercepted). On deploy, SIGTERM is usually sent, waited on for N seconds (timeout), then SIGKILL.

In PHP

pcntl_signal(SIGTERM, function () {
  $this->shouldStop = true; // stop worker loop after current task
});
pcntl_async_signals(true);

Kubernetes

terminationGracePeriodSeconds — the wait time between SIGTERM and SIGKILL. Default: 30 seconds.