Skip to content

Instantly share code, notes, and snippets.

@xdire
Created July 13, 2017 07:32
Show Gist options
  • Select an option

  • Save xdire/88932abb829ba6030e8098852f6bd68e to your computer and use it in GitHub Desktop.

Select an option

Save xdire/88932abb829ba6030e8098852f6bd68e to your computer and use it in GitHub Desktop.
PHP Application Signal Handling
<?php
// Declare Ticks as a required mechanics to handle Signals
declare(ticks = 1);
// Throw Error on
pcntl_signal(SIGINT, function($sig) {
throw new Exception("Interrupted by client signal: ".$sig,500);
});
echo "\nProgram started";
try {
// Do something
static $i = 0;
while (true) {
sleep(1);
echo "\nIterated: ".$i++;
}
} catch (Throwable $e) {
// Tell something to console
echo "\nError Happened: ".$e->getMessage()." [".$e->getCode()."]";
} finally {
// Do your closing procedures here
echo "\nFinished\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment