Skip to content

Instantly share code, notes, and snippets.

@welblaud
Last active February 17, 2023 16:02
Show Gist options
  • Save welblaud/6b76ce76c4551debe8b56ae943950afb to your computer and use it in GitHub Desktop.
Save welblaud/6b76ce76c4551debe8b56ae943950afb to your computer and use it in GitHub Desktop.
Signal catching in PHP
<?php
// turn on signal catching
pcntl_async_signals(true);
// handler
$sigHandler = static function(): void {
// do some cleanup
// report to user, whatever
// ...
exit(0);
};
// assign the handler to a signal
if (!pcntl_signal(SIGINT, $sigHandler)) { // SIGINT
// do some cleanup or report
exit(1);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment