Propagates termination-oriented signals to workers managed by the master process.
Description
This handler is intended to provide a default shutdown strategy for signals that require worker termination or graceful process unwinding.
Interfaces
Constants
Defines the default signals subscribed by the handler.
Properties
Indicates whether the handler is already processing a signal.
Methods
Creates a new default signal handler instance.
Handles a received signal for the current manager context.
Converts interactive termination signals to the signal used for worker propagation.
Sends the provided signal to all workers managed by the master process.
Defines the default signals subscribed by the handler.
public
array<int, Signal>
DEFAULT_SIGNALS
=
[\FastForward\Fork\Signal\Signal::Interrupt, \FastForward\Fork\Signal\Signal::Terminate, \FastForward\Fork\Signal\Signal::Quit]
Description
signals listened to by default
private
Signal
$escalationSignal
=
Signal::Kill
private
bool
$exitOnSignal
=
true
Indicates whether the handler is already processing a signal.
private
bool
$handling
=
false
Description
This flag prevents re-entrant shutdown handling when multiple signals are received during an ongoing termination sequence.
private
array<string|int, mixed>
$signals
=
self::DEFAULT_SIGNALS
private
bool
$waitForWorkers
=
true
Creates a new default signal handler instance.
public
__construct([
array<int, Signal>
$signals = self::DEFAULT_SIGNALS][,
bool
$waitForWorkers = true][,
bool
$exitOnSignal = true][, Signal
$escalationSignal = Signal::Kill]) : mixed
Parameters
Description
signals to subscribe to on the manager process
$waitForWorkers
:
bool
=
true
Description
whether the master process should wait for workers after propagation
$exitOnSignal
:
bool
=
true
Description
whether the master process should exit after handling the signal
Description
signal used when a second signal interrupts an in-progress shutdown
Handles a received signal for the current manager context.
public
__invoke(ForkManagerInterface
$manager, Signal
$signal) : void
Description
When invoked in the master process, the handler propagates an appropriate signal to managed workers. If signal handling is already in progress, the escalation signal is sent instead to accelerate shutdown.
Parameters
Description
the fork manager receiving the signal
Description
the signal that triggered the handler
Returns the signals subscribed by this handler.
public
signals() : array<int, Signal>
Return values
Description
the configured list of subscribed signals
Converts interactive termination signals to the signal used for worker propagation.
Description
Interrupt, quit, and terminate signals are normalized to a graceful termination request for workers. Any other signal is returned unchanged.
Parameters
Description
the original signal received by the handler
Return values
Description
the normalized signal to propagate to workers
Sends the provided signal to all workers managed by the master process.
private
terminateWorkers(ForkManagerInterface
$manager, Signal
$signal) : void
Description
No action is taken when the current process is not the master process.
Parameters
Description
the manager responsible for worker coordination
Description
the signal to send to managed workers