@@ -14,6 +14,11 @@ class SignalSocketHelper
1414 */
1515 private $ wasThereSignal ;
1616
17+ /**
18+ * @var int[]
19+ */
20+ private $ signals = [SIGTERM , SIGQUIT , SIGINT ];
21+
1722 public function __construct ()
1823 {
1924 $ this ->handlers = [];
@@ -25,30 +30,33 @@ public function beforeSocket()
2530 throw new \LogicException ('The handlers property should be empty but it is not. The afterSocket method might not have been called. ' );
2631 }
2732 if (null !== $ this ->wasThereSignal ) {
28- throw new \LogicException ('The wasSignal property should be null but it is not. The afterSocket method might not have been called. ' );
33+ throw new \LogicException ('The wasThereSignal property should be null but it is not. The afterSocket method might not have been called. ' );
2934 }
3035
3136 $ this ->wasThereSignal = false ;
3237
33- foreach ([ SIGTERM , SIGQUIT , SIGINT ] as $ signal ) {
38+ foreach ($ this -> signals as $ signal ) {
3439 /** @var callable $handler */
35- if ($ handler = pcntl_signal_get_handler (SIGTERM )) {
36- pcntl_signal ($ signal , function ($ signal ) use ($ handler ) {
37- $ this ->wasThereSignal = true ;
40+ $ handler = pcntl_signal_get_handler ($ signal );
3841
39- $ handler ($ signal );
40- });
42+ pcntl_signal ($ signal , function ($ signal ) use ($ handler ) {
43+ var_dump ('fuckk! ' );
44+ $ this ->wasThereSignal = true ;
4145
42- $ this ->handlers [$ signal ] = $ handler ;
43- }
46+ $ handler && $ handler ($ signal );
47+ });
48+
49+ $ handler && $ this ->handlers [$ signal ] = $ handler ;
4450 }
4551 }
4652
4753 public function afterSocket ()
4854 {
4955 $ this ->wasThereSignal = null ;
5056
51- foreach ($ this ->handlers as $ signal => $ handler ) {
57+ foreach ($ this ->signals as $ signal ) {
58+ $ handler = isset ($ this ->handlers [$ signal ]) ? $ this ->handlers [$ signal ] : SIG_DFL ;
59+
5260 pcntl_signal ($ signal , $ handler );
5361 }
5462
0 commit comments