function SignalHandler::exitWithLastSignal
Exits the process while communicating that the handled signal was what killed the process
This is different from doing exit(SIGINT), and is also different to a successful exit(0).
This should only be used when you received a signal and then handled it to gracefully shutdown and are now ready to shutdown.
``` $signal = SignalHandler::create([SignalHandler::SIGINT], function (string $signal, SignalHandler $handler) { // do cleanup here..
$handler->exitWithLastSignal(); });
// or...
$signal = SignalHandler::create([SignalHandler::SIGINT]);
while ($doingThings) { if ($signal->isTriggered()) { $signal->exitWithLastSignal(); }
// do more things } ```
Return value
never
See also
https://www.cons.org/cracauer/sigint.html
File
-
vendor/
seld/ signal-handler/ src/ SignalHandler.php, line 325
Class
- SignalHandler
- SignalHandler and factory
Namespace
Seld\SignalCode
public function exitWithLastSignal() : void {
$signal = $this->triggered ?? 'SIGINT';
$signal = defined($signal) ? constant($signal) : 2;
if (function_exists('posix_kill') && function_exists('posix_getpid')) {
pcntl_signal($signal, SIG_DFL);
posix_kill(posix_getpid(), $signal);
}
// just in case posix_kill above could not run
// not strictly correct but it's the best we can do here
exit(128 + $signal);
}