Supervisor Options - Comos/qpm GitHub Wiki
QPM has 3 supervision models: One For One, MultiGroupOneForOne and TaskFactory. They're different ways to maintain processes. Every mode has its own factory method. For example, the OneForOne supervisor could be create by Comos\Qpm\Supervision\Supervisor::oneForOne($options).
Common Options
worker
- Type callable or Comos\Qpm\Process\Runnable
- The worker would run in child process.
quantity
- Type integer
- Default 1
- The quantity of parallel children.
timeout
- Type float
- The max lifetime of child processes, unit is second.
- Default -1.0. It means no time limitation.
termTimeout
- Type float
- The max waiting time after a term signal has been sent to the child process. The unit is second.
- Default -1.0. It means no time limitation.
OneForOne Mode
Usage
Comos\Qpm\Supervision\Supervisor::oneForOne($options);
Scenario
All the child processes use a same callback function or a Runnable class.
Options
maxRestartTimes
- Type integer
- The max restarting times, often be used in conjunction with
withInSeconds
withInSeconds
- Type integer
- Often be used in conjunction with maxRestartTimes. Indicates that the child processes could restart specified times in the specified seconds.
Example 1
<?php
//The function justDoIt as the worker, to keep 3 child processes.
$config = ['worker' => 'justDoIt', 'quantity' => 3];
$sup = Comos\Qpm\Supervision\Supervisor::oneForOne($config);
$sup->start();
Example 2
<?php
//Foo::run() as the worker function, to keep 5 processes
//Allows to restart 100 times in 10 seconds,otherwise the main process would throws an exception.
$config = ['worker' => 'Foo', 'quantity' => 5, 'maxRestartTimes'=>100, 'withInSeconds'=>10];
$sup = Comos\Qpm\Supervision\Supervisor::oneForOne($config);
$sup->start();
MultiGroupOneForOne Mode
Useage
qpm\supervisor\Supervisor::oneForOne($options)
Scenario
Under MultiGroupOneForOne mode, you can manage one or more ways of OneForOne. The parameter of MultiGroupOneForOne is an array which contains one or more OneForOne options.
TaskFactoryMode Mode
Under the mode, the tasks would be produced by the task factory.
Method
Comos\Qpm\Supervision\Supervisor::taskFactoryMode($config)
Scenario
In some scenarios, every child process need different options, classes or running functions, you can use the task factory mode to produce tasks.
Options
factory callable The factory method to produce Runnable objects or Callable functions.
The type of the parameter could be Comos\Qpm\Process\Runnable or callable