-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #86 from jigarius/feature/handle-sigint
Handle SIGINT gracefully
- Loading branch information
Showing
12 changed files
with
219 additions
and
88 deletions.
There are no files selected for viewing
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
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
namespace Drall\Trait; | ||
|
||
trait SignalAwareTrait { | ||
|
||
/** | ||
* Register a signal listener. | ||
* | ||
* @param int $signo | ||
* Signal Number. | ||
* @param callable $handler | ||
* A callable event listener. | ||
* | ||
* @return bool | ||
* True if the listener was registered. | ||
*/ | ||
protected function registerSignalListener(int $signo, callable $handler): bool { | ||
if (!extension_loaded('pcntl')) { | ||
return FALSE; | ||
} | ||
|
||
declare(ticks = 1); | ||
\pcntl_signal($signo, $handler); | ||
|
||
return TRUE; | ||
} | ||
|
||
/** | ||
* Register a listener for SIGINT. | ||
* | ||
* @param callable $handler | ||
* A callable event listener. | ||
* | ||
* @return bool | ||
* True if the listener was registered. | ||
*/ | ||
protected function registerInterruptionListener(callable $handler): bool { | ||
if (!defined('SIGINT')) { | ||
return FALSE; | ||
} | ||
|
||
return self::registerSignalListener(SIGINT, $handler); | ||
} | ||
|
||
} |
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
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
Oops, something went wrong.