69 static $signals = array();
71 if (!$signals && extension_loaded(
'pcntl')) {
73 $constants = $pcntl->getConstants();
76 $constants = get_defined_constants(
true);
77 $constants = $constants[
'Core'];
79 foreach ($constants as
$name => $value) {
80 if (substr(
$name, 0, 3) ===
'SIG' &&
$name[3] !==
'_' && is_int($value)) {
81 $signals[$value] =
$name;
87 $level = isset($this->signalLevelMap[$signo]) ? $this->signalLevelMap[$signo] :
LogLevel::CRITICAL;
88 $signal = isset($signals[$signo]) ? $signals[$signo] : $signo;
89 $context = isset($siginfo) ? $siginfo : array();
90 $this->logger->log($level, sprintf(
'Program received signal %s', $signal),
$context);
92 if (!isset($this->previousSignalHandler[$signo])) {
96 if ($this->previousSignalHandler[$signo] ===
true || $this->previousSignalHandler[$signo] === SIG_DFL) {
97 if (extension_loaded(
'pcntl') && function_exists(
'pcntl_signal') && function_exists(
'pcntl_sigprocmask') && function_exists(
'pcntl_signal_dispatch')
98 && extension_loaded(
'posix') && function_exists(
'posix_getpid') && function_exists(
'posix_kill')) {
99 $restartSyscalls = isset($this->restartSyscalls[$signo]) ? $this->restartSyscalls[$signo] :
true;
100 pcntl_signal($signo, SIG_DFL, $restartSyscalls);
101 pcntl_sigprocmask(SIG_UNBLOCK, array($signo), $oldset);
102 posix_kill(posix_getpid(), $signo);
103 pcntl_signal_dispatch();
104 pcntl_sigprocmask(SIG_SETMASK, $oldset);
105 pcntl_signal($signo, array($this,
'handleSignal'), $restartSyscalls);
107 } elseif (is_callable($this->previousSignalHandler[$signo])) {
108 if (PHP_VERSION_ID >= 70100) {
109 $this->previousSignalHandler[$signo]($signo, $siginfo);
111 $this->previousSignalHandler[$signo]($signo);