Test Failed
Push — allow_fork_server ( abd9ca )
by Koldo
03:39
created

Child   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 13
c 1
b 0
f 0
dl 0
loc 24
ccs 0
cts 13
cp 0
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A fork() 0 22 4
1
<?php
2
3
4
namespace Antidot\React;
5
6
class Child
7
{
8
    public static function fork(int $numberOfWorkers, callable $asyncServer, int $numberOfFork = 0): void
9
    {
10
        $pid = pcntl_fork();
11
        if (-1 === $pid) {
12
            // @fail
13
            die('Fork failed');
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
14
        }
15
16
        if (0 === $pid) {
17
            $asyncServer();
18
            pcntl_waitpid($pid, $status);
19
            return;
20
        }
21
22
        // @parent
23
        $numberOfWorkers--;
24
        ++$numberOfFork;
25
        if ($numberOfWorkers > 0) {
26
            self::fork($numberOfWorkers, $asyncServer, $numberOfFork);
27
        }
28
29
        pcntl_waitpid($pid, $status);
30
    }
31
}
32