Complete API documentation for the SignalHandler plugin components and classes.
Interface for commands that can react to system signals.
Returns the list of signals to subscribe to.
Returns: array<int> Array of signal constants
Example:
public function getSubscribedSignals(): array
{
return [Signal::SIGINT, Signal::SIGTERM];
}Called when the command is about to terminate.
Parameters:
$exitCode(int) - The exit code that will be returned$interruptingSignal(int|null) - The signal that caused termination (if any)
Called when a SIGINT (Ctrl+C) signal is received.
Returns: int|false The exit code to return, or false to continue execution
Called when a SIGTERM signal is received.
Returns: int|false The exit code to return, or false to continue execution
Called when a SIGUSR1 signal is received.
Returns: int|false The exit code to return, or false to continue execution
Called when a SIGUSR2 signal is received.
Returns: int|false The exit code to return, or false to continue execution
Called when any signal is received.
Parameters:
$signal(int) - The signal that was received
Returns: int|false The exit code to return, or false to continue execution
Trait providing callback-based signal handling methods.
Registers signal handlers for the specified signals.
Parameters:
$signals(array) - Array of signal constants$callback(callable) - Callback function to execute when signal is received
Example:
$this->bindSignals([Signal::SIGINT, Signal::SIGTERM], function (int $signal) {
$this->isRunning = false;
});Removes all registered signal handlers and restores default signal behavior.
Convenience method that registers handlers for SIGINT and SIGTERM signals.
Parameters:
$callback(callable) - Callback function for graceful termination
Convenience method that registers handlers for debug signals (SIGUSR1, SIGUSR2, CTRL_BREAK).
Parameters:
$callback(callable) - Callback function for debug signal handling
Routes signals to the appropriate callback methods.
Parameters:
$signal(int) - The signal that was received$previousExitCode(int|false) - The previous exit code (if any)
Returns: int|false The exit code to return, or false to continue normal execution
Core signal registration and management class.
Register a signal handler.
Parameters:
$signal(int) - The signal to register (e.g., SIGINT, SIGTERM)$signalHandler(callable) - The handler callback
Throws: RuntimeException When signal handling is not supported
Handle a signal by calling all registered handlers.
Parameters:
$signal(int) - The signal that was received
Unregister all signal handlers and restore defaults.
Schedule an alarm signal.
Parameters:
$seconds(int) - Seconds until alarm
Check if signal handling is supported on this platform.
Returns: bool True if signal handling is supported
Operating system detection and platform-specific signal availability checking.
Get the operating system family.
Returns: string Operating system family (linux, windows, macos, unknown)
Check if the current platform is Linux.
Returns: bool True if Linux
Check if the current platform is Windows.
Returns: bool True if Windows
Check if the current platform is macOS.
Returns: bool True if macOS
Check if signal handling is available on the current platform.
Returns: bool True if signal handling is available
Signal constants for cross-platform signal handling.
Signal::SIGTERM(15) - Termination signalSignal::SIGINT(2) - Interrupt signal (Ctrl+C)Signal::SIGQUIT(3) - Quit signalSignal::SIGUSR1(10) - User signal 1Signal::SIGUSR2(12) - User signal 2Signal::SIGHUP(1) - Hangup signalSignal::SIGKILL(9) - Kill signal
Signal::CTRL_C(2) - Ctrl+C eventSignal::CTRL_BREAK(3) - Ctrl+Break event
Get all available signal constants.
Returns: array<string, int> Array of signal name to constant mapping
Check if a signal number is valid.
Parameters:
$signalNumber(int) - Signal number to validate
Returns: bool True if valid
Get signal name by number.
Parameters:
$signalNumber(int) - Signal number
Returns: string|null Signal name or null if not found
Service for managing signal handling through CakePHP's service container.
Get or create the signal event listener.
Returns: SignalEventListener The event listener instance
Check if signal handling is supported on this platform.
Returns: bool True if supported
Check if signal handling is enabled.
Returns: bool True if enabled
Check if a command implements signal handling.
Parameters:
$command(object) - The command to check
Returns: bool True if command implements SignalableCommandInterface
Register signal handlers for a command.
Parameters:
$command(SignalableCommandInterface) - The command to register handlers for
Returns: SignalRegistry|null The signal registry or null if not enabled
Unregister signal handlers for a command.
Parameters:
$command(SignalableCommandInterface) - The command to unregister handlers for
Handle a signal for a command.
Parameters:
$command(SignalableCommandInterface) - The command$signal(int) - The signal that was received
Returns: int|false The exit code or false to continue execution
CakePHP event listener for automatic signal handling integration.
Returns a list of events this object is implementing.
Returns: array<string, mixed> Event mapping
Handle Command.beforeExecute event - registers signal handlers.
Parameters:
$event(EventInterface) - The event object
Handle Command.afterExecute event - cleans up signal handlers.
Parameters:
$event(EventInterface) - The event object
Get the current signal registry.
Returns: SignalRegistry|null The signal registry or null
Get the current command.
Returns: SignalableCommandInterface|null The current command or null
Windows-specific signal handling using Windows API.
Register a Windows signal handler.
Parameters:
$signal(int) - The signal to register$handler(callable) - The handler callback
Unregister Windows signal handlers.
Dispatched before command execution to register signal handlers.
Data:
args(Arguments) - Command arguments
Dispatched after command execution to clean up signal handlers.
Data:
args(Arguments) - Command argumentsresult(int|null) - Command result
Dispatched when a signal is received.
Data:
signal(int) - The signal that was receivedcommand(SignalableCommandInterface) - The command that received the signal