Skip to content

Latest commit

 

History

History
40 lines (31 loc) · 1.6 KB

Ref_SignalSafeWorkProcessor_class.md

File metadata and controls

40 lines (31 loc) · 1.6 KB

SignalSafeWorkProcessor Class

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 calls pcntl_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.

Additional Methods

  • public static function installSignalHandler (array $signals = [\SIGTERM, \SIGINT])
    Installs a signal handler that will clear the isAlive() flag.
    The registered signals will not immediately terminate the program anymore, giving the job handler callback enough time to finish their execution. If isAlive() is false after processNextJob() returns, you should exit the program.
    • $signals: An array of signal numbers for which to install the signal handler. By default, the signal handler is installed for SIGTERM and SIGINT, two signals commonly used to cleanly stop running processes.
  • public static function isAlive (): bool
    Returns true as long as no registered signal was received.
  • public static function lastSignal (): ?int
    Returns the number of the last signal received, or null if no signal has been received since the signal handler was set up.