Test Failed
Pull Request — 2.x.x (#13)
by Koldo
10:13
created

Child::fork()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 22
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 12
c 1
b 0
f 0
dl 0
loc 22
ccs 0
cts 13
cp 0
rs 9.8666
cc 4
nc 4
nop 3
crap 20
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