@@ -27,11 +27,31 @@ public function __construct(?int $max_childs = null, bool $kill_childs = true)
2727 $ this ->kill_childs = $ kill_childs ;
2828
2929 register_tick_function ([$ this , "tick " ]);
30- pcntl_signal (SIGCHLD , SIG_IGN ); // ignores the SIGCHLD signal
30+ #pcntl_signal(SIGCHLD, SIG_IGN); // ignores the SIGCHLD signal
31+
32+ pcntl_async_signals (true );
33+
34+ pcntl_signal (SIGCHLD , function ($ signo , $ status ) {
35+ while (true ) {
36+ $ pid = pcntl_waitpid (-1 , $ processState , WNOHANG | WUNTRACED );
37+
38+ if ($ pid <= 0 ) {
39+ break ;
40+ }
41+
42+ foreach ($ this ->childs as $ key => $ child ) {
43+ if ($ pid === $ child ){
44+ self ::breakpoint ("removed child from signal handler " );
45+ unset($ this ->childs [$ key ]);
46+ }
47+ }
48+ }
49+ });
3150 }
3251
3352 public function checkChilds (): bool
3453 {
54+ return false ;
3555 self ::breakpoint ("checkChilds() " );
3656 $ removed = 0 ;
3757 foreach ($ this ->childs as $ key => $ child ) {
@@ -86,7 +106,7 @@ protected function _parallel(Closure $closure, string $process_title = null, arr
86106 public function parallel (Closure $ closure , string $ process_title = null , ...$ args )
87107 {
88108 if (count ($ this ->childs ) > $ this ->max_childs /2 ){
89- $ this ->checkChilds ();
109+ # $this->checkChilds();
90110 }
91111 if ($ this ->hasQueue ()){
92112 self ::breakpoint ("resolving queue before parallel() " );
@@ -109,7 +129,7 @@ public function resolveQueue(): void
109129
110130 if (count ($ this ->childs ) >= $ this ->max_childs ){
111131 self ::breakpoint ("resolveQueue() -> too many childs, trying to remove... " .PHP_EOL ."check childs from resolveQueue() " );
112- if (!$ this ->checkChilds ()){
132+ if (true || !$ this ->checkChilds ()){
113133 self ::breakpoint ("resolveQueue() exited because of too many childs " );
114134 return ;
115135 }
@@ -230,7 +250,7 @@ public function waitChilds(): void
230250 {
231251 while ($ this ->hasChilds ()){
232252 self ::breakpoint ("there are still childs " );
233- $ this ->checkChilds ();
253+ # $this->checkChilds();
234254 usleep (10000 );
235255 }
236256 }
0 commit comments