Created
July 13, 2017 07:32
-
-
Save xdire/88932abb829ba6030e8098852f6bd68e to your computer and use it in GitHub Desktop.
PHP Application Signal Handling
This file contains hidden or 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 | |
| // 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