1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Process communication pipe |
4
|
|
|
* User: moyo |
5
|
|
|
* Date: 28/12/2017 |
6
|
|
|
* Time: 11:13 AM |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace Carno\Process; |
10
|
|
|
|
11
|
|
|
use Carno\Process\Chips\Forking; |
12
|
|
|
use Swoole\Process as SWProcess; |
|
|
|
|
13
|
|
|
use Throwable; |
14
|
|
|
|
15
|
|
|
class Piping |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* @var Program |
19
|
|
|
*/ |
20
|
|
|
private $backend = null; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Piping constructor. |
24
|
|
|
* @param Program $backend |
25
|
|
|
*/ |
26
|
|
|
public function __construct(Program $backend) |
27
|
|
|
{ |
28
|
|
|
$this->backend = $backend->forked($this); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* process bootstrap |
33
|
|
|
*/ |
34
|
|
|
final public function bootstrap() : void |
35
|
|
|
{ |
36
|
|
|
foreach ([SIGINT, SIGTERM] as $sig) { |
37
|
|
|
SWProcess::signal($sig, function (int $sig) { |
38
|
|
|
$this->backend->shutdown($sig); |
39
|
|
|
}); |
40
|
|
|
} |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* message receiving |
45
|
|
|
*/ |
46
|
|
|
final public function reading() : void |
47
|
|
|
{ |
48
|
|
|
swoole_event_add($this->backend->process()->pipe, function () { |
|
|
|
|
49
|
|
|
$recv = $this->backend->process()->read(); |
50
|
|
|
try { |
51
|
|
|
list($name, $arguments) = unserialize($recv); |
52
|
|
|
$this->backend->$name(...$arguments); |
53
|
|
|
} catch (Throwable $e) { |
54
|
|
|
logger('process')->notice('Dispatch failed', ['err' => get_class($e), 'msg' => $e->getMessage()]); |
55
|
|
|
} |
56
|
|
|
}); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @param string $name |
61
|
|
|
* @param array $arguments |
62
|
|
|
* @return mixed |
63
|
|
|
*/ |
64
|
|
|
final public function __call(string $name, array $arguments = []) |
65
|
|
|
{ |
66
|
|
|
if (null !== $process = $this->backend->process()) { |
67
|
|
|
return $process->write(serialize([$name, $arguments])); |
68
|
|
|
} else { |
69
|
|
|
return $this->backend->$name(...$arguments); |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* call from master/parent and will redirect to child-process |
75
|
|
|
* @see Forking::shutdown |
76
|
|
|
*/ |
77
|
|
|
final public function shutdown() : void |
78
|
|
|
{ |
79
|
|
|
$this->__call('shutdown'); |
80
|
|
|
Master::wait($this->backend->process()->pid ?? -2); |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|
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:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths