This class is an extension of the original WorkProcessor.
Key differences:
- It has the
installSignalHandler()
method. - It has the
isAlive()
test method. - It has the
lastSignal()
getter method. - The
processNextJob()
method always callspcntl_signal_dispatch
before returning.
All instances are alive
until one of the registered signals is sent to the process.
If your worker script has a loop around the processNextJob()
call,
check isAlive()
in the loop condition.
public static function installSignalHandler (array $signals = [\SIGTERM, \SIGINT])
Installs a signal handler that will clear theisAlive()
flag.
The registered signals will not immediately terminate the program anymore, giving the job handler callback enough time to finish their execution. IfisAlive()
is false afterprocessNextJob()
returns, you shouldexit
the program.$signals
: An array of signal numbers for which to install the signal handler. By default, the signal handler is installed forSIGTERM
andSIGINT
, two signals commonly used to cleanly stop running processes.
public static function isAlive (): bool
Returnstrue
as long as no registered signal was received.public static function lastSignal (): ?int
Returns the number of the last signal received, ornull
if no signal has been received since the signal handler was set up.