Issues (11)

src/Master.php (1 issue)

Severity
1
<?php
2
/**
3
 * Master process
4
 * User: moyo
5
 * Date: 28/12/2017
6
 * Time: 12:08 PM
7
 */
8
9
namespace Carno\Process;
10
11
use Swoole\Process as SWProcess;
12
13
class Master
14
{
15
    /**
16
     * @var bool
17
     */
18
    private static $watched = false;
19
20
    /**
21
     * @var array
22
     */
23
    private static $exited = [];
24
25
    /**
26
     * @param int $pid
27
     */
28
    public static function watch(int $pid) : void
0 ignored issues
show
The parameter $pid is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

28
    public static function watch(/** @scrutinizer ignore-unused */ int $pid) : void

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
29
    {
30
        self::$watched || self::$watched = SWProcess::signal(SIGCHLD, function () {
31
            while ($ex = SWProcess::wait(false)) {
32
                Progress::exited($ex['pid'], $ex['signal'], $ex['code']);
33
            }
34
        });
35
    }
36
37
    /**
38
     * @param int $pid
39
     */
40
    public static function wait(int $pid) : void
41
    {
42
        if (isset(self::$exited[$pid])) {
43
            Progress::exited(...self::$exited[$pid]);
44
        } else {
45
            if (false !== $ex = SWProcess::wait(true)) {
46
                if ($ex['pid'] === $pid) {
47
                    Progress::exited($ex['pid'], $ex['signal'], $ex['code']);
48
                } else {
49
                    self::$exited[$ex['pid']] = [$ex['pid'], $ex['signal'], $ex['code']];
50
                }
51
            }
52
        }
53
    }
54
}
55