-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathRunner.php
52 lines (40 loc) · 1.35 KB
/
Runner.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
declare(strict_types=1);
namespace Manyou\WorkermanSymfonyRuntime;
use Chubbyphp\WorkermanRequestHandler\OnMessageInterface;
use Closure;
use InvalidArgumentException;
use Symfony\Component\HttpKernel\KernelInterface;
use Symfony\Component\Runtime\RunnerInterface;
use Workerman\Worker;
use function get_debug_type;
use function sprintf;
class Runner implements RunnerInterface
{
public function __construct(
private Closure $appFactory,
private string $socket,
private int $workers,
private string $pidFile,
private string $logFile,
) {
}
public function run(): int
{
$worker = new Worker($this->socket);
$worker->count = $this->workers;
$worker::$pidFile = $this->pidFile;
$worker::$logFile = $this->logFile;
$worker->onWorkerStart = function (Worker $worker): void {
$kernel = ($this->appFactory)();
if (! $kernel instanceof KernelInterface) {
throw new InvalidArgumentException(sprintf('Expecting "%s" while given "%s".', KernelInterface::class, get_debug_type($kernel)));
}
$kernel->boot();
$container = $kernel->getContainer();
$worker->onMessage = $container->get(OnMessageInterface::class);
};
Worker::runAll();
return 0;
}
}