DefaultSignalHandler

Class
Final: Yes

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.

Table of Contents

Interfaces

SignalHandlerInterface

Defines the contract for manager-owned signal handlers.

Constants

DEFAULT_SIGNALS

Defines the default signals subscribed by the handler.

 = [\FastForward\Fork\Signal\Signal::Interrupt, \FastForward\Fork\Signal\Signal::Terminate, \FastForward\Fork\Signal\Signal::Quit]

Properties

$handling

Indicates whether the handler is already processing a signal.

 : bool
 : array<string|int, mixed>

Methods

__construct()

Creates a new default signal handler instance.

 : mixed
__invoke()

Handles a received signal for the current manager context.

 : void
signals()

Returns the signals subscribed by this handler.

 : array<int, Signal>
propagationSignal()

Converts interactive termination signals to the signal used for worker propagation.

 : Signal
terminateWorkers()

Sends the provided signal to all workers managed by the master process.

 : void
Constants

Constants

DEFAULT_SIGNALS

Public

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

Properties

$handling

Private

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.

$signals

Private Read-only
private array<string|int, mixed> $signals = self::DEFAULT_SIGNALS
Methods

__construct()

Public

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
$signals : array<int, Signal> = self::DEFAULT_SIGNALS

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

$escalationSignal : Signal = Signal::Kill

Description

signal used when a second signal interrupts an in-progress shutdown

__invoke()

Public

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

$signal : Signal

Description

the signal that triggered the handler

signals()

Public

Returns the signals subscribed by this handler.

public signals() : array<int, Signal>
Return values
array<int, Signal>

Description

the configured list of subscribed signals

propagationSignal()

Private

Converts interactive termination signals to the signal used for worker propagation.

private propagationSignal(Signal  $signal) : Signal

Description

Interrupt, quit, and terminate signals are normalized to a graceful termination request for workers. Any other signal is returned unchanged.

Parameters
$signal : Signal

Description

the original signal received by the handler

Return values

Description

the normalized signal to propagate to workers

terminateWorkers()

Private

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

$signal : Signal

Description

the signal to send to managed workers