ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
Monolog\SignalHandler Class Reference

Monolog POSIX signal handler. More...

+ Collaboration diagram for Monolog\SignalHandler:

Public Member Functions

 __construct (LoggerInterface $logger)
 
 registerSignalHandler ($signo, $level=LogLevel::CRITICAL, $callPrevious=true, $restartSyscalls=true, $async=true)
 
 handleSignal ($signo, array $siginfo=null)
 

Private Attributes

 $logger
 
 $previousSignalHandler = array()
 
 $signalLevelMap = array()
 
 $signalRestartSyscalls = array()
 

Detailed Description

Monolog POSIX signal handler.

Author
Robert Gust-Bardon rober.nosp@m.t@gu.nosp@m.st-ba.nosp@m.rdon.nosp@m..org

Definition at line 23 of file SignalHandler.php.

Constructor & Destructor Documentation

◆ __construct()

Monolog\SignalHandler::__construct ( LoggerInterface  $logger)

Definition at line 31 of file SignalHandler.php.

32  {
33  $this->logger = $logger;
34  }

Member Function Documentation

◆ handleSignal()

Monolog\SignalHandler::handleSignal (   $signo,
array  $siginfo = null 
)

Definition at line 67 of file SignalHandler.php.

References $context, and $name.

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  // HHVM 3.24.2 returns an empty array.
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  }
$context
Definition: webdav.php:25

◆ registerSignalHandler()

Monolog\SignalHandler::registerSignalHandler (   $signo,
  $level = LogLevel::CRITICAL,
  $callPrevious = true,
  $restartSyscalls = true,
  $async = true 
)

Definition at line 36 of file SignalHandler.php.

References $handler.

37  {
38  if (!extension_loaded('pcntl') || !function_exists('pcntl_signal')) {
39  return $this;
40  }
41 
42  if ($callPrevious) {
43  if (function_exists('pcntl_signal_get_handler')) {
44  $handler = pcntl_signal_get_handler($signo);
45  if ($handler === false) {
46  return $this;
47  }
48  $this->previousSignalHandler[$signo] = $handler;
49  } else {
50  $this->previousSignalHandler[$signo] = true;
51  }
52  } else {
53  unset($this->previousSignalHandler[$signo]);
54  }
55  $this->signalLevelMap[$signo] = $level;
56  $this->signalRestartSyscalls[$signo] = $restartSyscalls;
57 
58  if (function_exists('pcntl_async_signals') && $async !== null) {
59  pcntl_async_signals($async);
60  }
61 
62  pcntl_signal($signo, array($this, 'handleSignal'), $restartSyscalls);
63 
64  return $this;
65  }
$handler

Field Documentation

◆ $logger

Monolog\SignalHandler::$logger
private

Definition at line 25 of file SignalHandler.php.

◆ $previousSignalHandler

Monolog\SignalHandler::$previousSignalHandler = array()
private

Definition at line 27 of file SignalHandler.php.

◆ $signalLevelMap

Monolog\SignalHandler::$signalLevelMap = array()
private

Definition at line 28 of file SignalHandler.php.

◆ $signalRestartSyscalls

Monolog\SignalHandler::$signalRestartSyscalls = array()
private

Definition at line 29 of file SignalHandler.php.


The documentation for this class was generated from the following file: