@@ -27,11 +27,31 @@ public function __construct(?int $max_childs = null, bool $kill_childs = true)
27
27
$ this ->kill_childs = $ kill_childs ;
28
28
29
29
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
+ });
31
50
}
32
51
33
52
public function checkChilds (): bool
34
53
{
54
+ return false ;
35
55
self ::breakpoint ("checkChilds() " );
36
56
$ removed = 0 ;
37
57
foreach ($ this ->childs as $ key => $ child ) {
@@ -86,7 +106,7 @@ protected function _parallel(Closure $closure, string $process_title = null, arr
86
106
public function parallel (Closure $ closure , string $ process_title = null , ...$ args )
87
107
{
88
108
if (count ($ this ->childs ) > $ this ->max_childs /2 ){
89
- $ this ->checkChilds ();
109
+ # $this->checkChilds();
90
110
}
91
111
if ($ this ->hasQueue ()){
92
112
self ::breakpoint ("resolving queue before parallel() " );
@@ -109,7 +129,7 @@ public function resolveQueue(): void
109
129
110
130
if (count ($ this ->childs ) >= $ this ->max_childs ){
111
131
self ::breakpoint ("resolveQueue() -> too many childs, trying to remove... " .PHP_EOL ."check childs from resolveQueue() " );
112
- if (!$ this ->checkChilds ()){
132
+ if (true || !$ this ->checkChilds ()){
113
133
self ::breakpoint ("resolveQueue() exited because of too many childs " );
114
134
return ;
115
135
}
@@ -230,7 +250,7 @@ public function waitChilds(): void
230
250
{
231
251
while ($ this ->hasChilds ()){
232
252
self ::breakpoint ("there are still childs " );
233
- $ this ->checkChilds ();
253
+ # $this->checkChilds();
234
254
usleep (10000 );
235
255
}
236
256
}
0 commit comments