Last active
February 17, 2023 16:02
-
-
Save welblaud/6b76ce76c4551debe8b56ae943950afb to your computer and use it in GitHub Desktop.
Signal catching in PHP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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