Manual
Production
Sizing, reloads, logging and shutdown.
Introduction#
--workers, --max-memory and --max-requests size and recycle worker processes; --watchdog replaces one whose event loop has stopped turning. A reload (SIGHUP) restarts every worker on the current code without dropping the process; a stop drains requests within --grace seconds. See Production for the defaults and what each one is for.
Guides#
- Production – Sizing, reloads, logging, limits and the phasync extension.
Examples#
- All examples of this topic – 15 with their output.
Reference#
StopReason– Why a worker stops, see WorkerStoppingException.Swerve::log– The log of this process: swerve's own PSR-3 logger, in its format (the time, this worker's slot).Swerve::setLog– Replace the logger that Swerve::log returns.Swerve::draining– Whether this worker drains: it is shutting down, reloading or being recycled.Swerve::onShutdown– Run $callback when this worker must now close its connections: for an upgraded connection, to say goodbye in its protocol and end it.Swerve::awaitShutdown– Wait until this worker must close its connections, see Swerve::onShutdown.Swerve::ini– php.ini settings a package needs in every swerve process. Call it from a file listed in your package's composer.json files: Composer loads it after swerve's own, as the master starts. swerve applies the settings with its startup restart, over its own settings; an explicit -d on the command line still wins.Swerve::onWorkerStart– Run $callback in every worker as it starts, before the application loads, inside the worker's event loop, so it may start coroutines that run for the worker's life. Register it the way Swerve::ini says; calls after startup change nothing. A callback that throws stops the worker, as an application that fails to load does.Swerve::getVersion– The installed version, as Composer knows it: 0.1.0, or dev-main in a checkout.WorkerStoppingException– Thrown into the coroutines still running when a worker stops, once its requests have finished (or its drain time is over): clean up at once, then let it end; the worker exits shortly after, whether or not they have. A phasync ShutdownException, so a CancelledException: code that only needs to stop catches nothing. $reason says why, for telling a client what happens next.