1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of the sj-i/php-profiler package. |
5
|
|
|
* |
6
|
|
|
* (c) sji <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
declare(strict_types=1); |
13
|
|
|
|
14
|
|
|
namespace PhpProfiler\Command\Inspector; |
15
|
|
|
|
16
|
|
|
use Amp\Loop; |
|
|
|
|
17
|
|
|
use Amp\Promise; |
|
|
|
|
18
|
|
|
use Amp\Parallel\Context; |
|
|
|
|
19
|
|
|
use Symfony\Component\Console\Command\Command; |
|
|
|
|
20
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
|
|
|
21
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
|
|
|
22
|
|
|
|
23
|
|
|
class DaemonCommand extends Command |
24
|
|
|
{ |
25
|
|
|
public function configure(): void |
26
|
|
|
{ |
27
|
|
|
$this->setName('inspector:daemon') |
28
|
|
|
->setDescription('periodically get running function name from an outer process or thread'); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @param InputInterface $input |
33
|
|
|
* @param OutputInterface $output |
34
|
|
|
* @return int |
35
|
|
|
*/ |
36
|
|
|
public function execute(InputInterface $input, OutputInterface $output): int |
37
|
|
|
{ |
38
|
|
|
$context = Context\create(__DIR__ . '/Worker/php-searcher.php'); |
|
|
|
|
39
|
|
|
/** @var int $searcher_pid */ |
40
|
|
|
$searcher_pid = Promise\wait($context->start()); |
|
|
|
|
41
|
|
|
/** @var int[] $pid_list */ |
42
|
|
|
$pid_list = Promise\wait($context->receive()); |
43
|
|
|
$readers = []; |
44
|
|
|
foreach ($pid_list as $pid) { |
45
|
|
|
$context = Context\create(__DIR__ . '/Worker/php-reader.php'); |
46
|
|
|
Promise\wait($context->start()); |
47
|
|
|
Promise\wait($context->send($pid)); |
48
|
|
|
$readers[$pid] = $context; |
49
|
|
|
} |
50
|
|
|
Loop::run(function () use (&$readers, $output) { |
51
|
|
|
Loop::repeat(10, function () use (&$readers, $output) { |
52
|
|
|
if (empty($readers)) { |
53
|
|
|
return false; |
54
|
|
|
} |
55
|
|
|
$promises = []; |
56
|
|
|
foreach ($readers as $pid => $reader) { |
57
|
|
|
if (!$reader->isRunning()) { |
58
|
|
|
unset($readers[$pid]); |
59
|
|
|
continue; |
60
|
|
|
} |
61
|
|
|
$promises[] = \Amp\call( |
|
|
|
|
62
|
|
|
function () use ($reader, &$readers, $pid, $output) { |
63
|
|
|
/** @var string */ |
64
|
|
|
unset($readers[$pid]); |
65
|
|
|
$result = yield $reader->receive(); |
66
|
|
|
$output->write($result); |
67
|
|
|
$readers[$pid] = $reader; |
68
|
|
|
} |
69
|
|
|
); |
70
|
|
|
} |
71
|
|
|
yield $promises; |
72
|
|
|
}); |
73
|
|
|
}); |
74
|
|
|
|
75
|
|
|
return 0; |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|
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