Back to DaemonApplication class

Method setupSignalHandlers

protected bool
setupSignalHandlers
()
Method to attach the DaemonApplication signal handler to the known signals. Applications can override these handlers by using the pcntl_signal() function and attaching a different callback method.
Returns
  • bool
Since
  • 1.7.0
-
  • \Joomla\CMS\Application\pcntl_signal()

Method setupSignalHandlers - Source code

/**
 * Method to attach the DaemonApplication signal handler to the known signals.  Applications
 * can override these handlers by using the pcntl_signal() function and attaching a different
 * callback method.
 *
 * @return  boolean
 *
 * @since   1.7.0
 * @see     pcntl_signal()
 */
protected function setupSignalHandlers()
{
    // We add the error suppression for the loop because on some platforms some constants are not defined.
    foreach (self::$signals as $signal) {
        // Ignore signals that are not defined.
        if (!\defined($signal) || !\is_int(\constant($signal)) || \constant($signal) === 0) {
            // Define the signal to avoid notices.
            Log::add('Signal "' . $signal . '" not defined. Defining it as null.', Log::DEBUG);
            \define($signal, null);
            // Don't listen for signal.
            continue;
        }
        // Attach the signal handler for the signal.
        if (!$this->pcntlSignal(\constant($signal), array('DaemonApplication', 'signal'))) {
            Log::add(sprintf('Unable to reroute signal handler: %s', $signal), Log::EMERGENCY);
            return false;
        }
    }
    return true;
}