68 {
69 static $signals = array();
70
71 if (!$signals && extension_loaded('pcntl')) {
72 $pcntl = new ReflectionExtension('pcntl');
73 $constants = $pcntl->getConstants();
74 if (!$constants) {
75
76 $constants = get_defined_constants(true);
77 $constants = $constants['Core'];
78 }
79 foreach ($constants as
$name => $value) {
80 if (substr(
$name, 0, 3) ===
'SIG' &&
$name[3] !==
'_' && is_int($value)) {
81 $signals[$value] =
$name;
82 }
83 }
84 unset($constants);
85 }
86
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);
91
92 if (!isset($this->previousSignalHandler[$signo])) {
93 return;
94 }
95
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);
106 }
107 } elseif (is_callable($this->previousSignalHandler[$signo])) {
108 if (PHP_VERSION_ID >= 70100) {
109 $this->previousSignalHandler[$signo]($signo, $siginfo);
110 } else {
111 $this->previousSignalHandler[$signo]($signo);
112 }
113 }
114 }