This is automatic generated document for things in Swow\Process\ProcessManagerTrait class

Trait ProcessManagerTrait

Shared process manager lifecycle.

The manager starts workers and controls their life cycle. It restarts workers that exit with an error. On POSIX, SIGUSR1 starts a graceful reload. On Windows, SIGBREAK starts it. SIGTERM and SIGINT start a graceful stop.

Properties

protected $intCoroutine protected $managedCoroutineCount protected $managingCoroutines protected $maxRestartCount protected $maxWaitTime protected $onWorkerExit protected $reloadCoroutine protected $reloadTaskCoroutine protected $reloading protected $restartCounts protected $running protected $termCoroutine protected $watcherCoroutines protected $workerCount protected $workers

Methods

Method __construct

public function __construct ( int $workerCount )

Param int $workerCount Number of workers. 0 selects the CPU count.

Method createWorker

protected abstract function createWorker ( int $id ) : ChildProcess

Method enforceWorkerShutdownTimeout

protected function enforceWorkerShutdownTimeout ( ) : void

Method getWorkerCount

public function getWorkerCount ( ) : int

Method handleSignals

protected function handleSignals ( ) : void

Run the manager loop.

The manager handles signals and collects workers. Each worker has a wait coroutine. The coroutine restarts the worker when necessary. The manager waits for the coroutines that it owns. After stop, the signal coroutines exit by timeout.

Method onWorkerExit

public function onWorkerExit ( Closure(int $workerId, int $workerPid, ProcessExitStatus $status): void $callback ) : static

Set the worker exit callback.

The callback runs in the manager process. It receives the worker ID, PID, and exit status.

Method reload

public function reload ( ) : void

Reload all workers one by one without downtime.

Method runManagedCoroutine

protected function runManagedCoroutine ( Closure $callback ) : Coroutine

Method setMaxRestartCount

public function setMaxRestartCount ( int $count ) : static

Maximum number of restarts after an error. The manager does not restart the worker after this limit.

Method setMaxWaitTime

public function setMaxWaitTime ( int $seconds ) : static

Maximum time in seconds to wait for a graceful stop. The manager uses SIGKILL after this time.

Method startManager

protected function startManager ( ) : void

Method stop

public function stop ( ) : void

Stop all workers gracefully.

Method watchWorker

protected function watchWorker ( int $id , ?ChildProcess $process ) : void

Start a monitor coroutine for a worker. The coroutine restarts the worker according to the restart policy.


Copyright 2022 the Swow contributors