Issues (11)

src/Master.php (1 issue)

Labels
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;
0 ignored issues
show
The type Swoole\Process was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
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
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