|
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\Inspector\Daemon\Dispatcher; |
|
15
|
|
|
|
|
16
|
|
|
use PhpProfiler\Inspector\Daemon\Reader\Context\PhpReaderContext; |
|
17
|
|
|
use PhpProfiler\Inspector\Daemon\Reader\Context\PhpReaderContextCreator; |
|
18
|
|
|
use Amp\Promise; |
|
|
|
|
|
|
19
|
|
|
|
|
20
|
|
|
final class WorkerPool |
|
21
|
|
|
{ |
|
22
|
|
|
/** @var array<int, PhpReaderContext> */ |
|
23
|
|
|
private array $contexts; |
|
24
|
|
|
|
|
25
|
|
|
/** @var array<int, bool> */ |
|
26
|
|
|
private array $is_free_list; |
|
27
|
|
|
|
|
28
|
|
|
public function __construct(PhpReaderContext ...$contexts) |
|
29
|
|
|
{ |
|
30
|
|
|
$this->contexts = $contexts; |
|
31
|
|
|
$this->is_free_list = array_fill(0, count($contexts), true); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
public static function create(PhpReaderContextCreator $creator, int $number): self |
|
35
|
|
|
{ |
|
36
|
|
|
$contexts = []; |
|
37
|
|
|
$started = []; |
|
38
|
|
|
for ($i = 0; $i < $number; $i++) { |
|
39
|
|
|
$context = $creator->create(); |
|
40
|
|
|
$started[] = $context->start(); |
|
41
|
|
|
$contexts[] = $context; |
|
42
|
|
|
} |
|
43
|
|
|
Promise\wait(Promise\all($started)); |
|
|
|
|
|
|
44
|
|
|
return new self(...$contexts); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
public function getFreeWorker(): ?PhpReaderContext |
|
48
|
|
|
{ |
|
49
|
|
|
foreach ($this->contexts as $key => $context) { |
|
50
|
|
|
if ($this->is_free_list[$key]) { |
|
51
|
|
|
$this->is_free_list[$key] = false; |
|
52
|
|
|
return $context; |
|
53
|
|
|
} |
|
54
|
|
|
} |
|
55
|
|
|
return null; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
public function returnWorkerToPool(PhpReaderContext $context_to_return): void |
|
59
|
|
|
{ |
|
60
|
|
|
foreach ($this->contexts as $key => $context) { |
|
61
|
|
|
if ($context === $context_to_return) { |
|
62
|
|
|
$this->is_free_list[$key] = true; |
|
63
|
|
|
} |
|
64
|
|
|
} |
|
65
|
|
|
} |
|
66
|
|
|
} |
|
67
|
|
|
|
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