-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathRuntime.php
59 lines (45 loc) · 1.67 KB
/
Runtime.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
53
54
55
56
57
58
59
<?php
declare(strict_types=1);
namespace Manyou\WorkermanSymfonyRuntime;
use ReflectionFunction;
use Symfony\Component\Runtime\ResolverInterface;
use Symfony\Component\Runtime\RunnerInterface;
use Symfony\Component\Runtime\SymfonyRuntime;
use function md5;
class Runtime extends SymfonyRuntime
{
private string $socket;
private int $workers;
private string $pidFile;
private string $logFile;
public function __construct(array $options = [])
{
$this->socket = $options['socket']
?? $_SERVER['APP_RUNTIME_SOCKET']
?? $_ENV['APP_RUNTIME_SOCKET']
?? 'http://0.0.0.0:' . ($_SERVER['PORT'] ?? $_ENV['PORT'] ?? 3000);
$this->workers = (int) ($options['workers']
?? $_SERVER['APP_RUNTIME_WORKERS']
?? $_ENV['APP_RUNTIME_WORKERS']
?? 16);
$hash = md5(__FILE__);
$this->pidFile = $options['pid_file']
?? $_SERVER['APP_RUNTIME_PID_FILE']
?? $_ENV['APP_RUNTIME_PID_FILE']
?? "/tmp/workerman-$hash.pid";
$this->logFile = $options['log_file']
?? $_SERVER['APP_RUNTIME_LOG_FILE']
?? $_ENV['APP_RUNTIME_LOG_FILE']
?? "/tmp/workerman-$hash.log";
parent::__construct($options);
}
public function getRunner(?object $application): RunnerInterface
{
return new Runner($application, $this->socket, $this->workers, $this->pidFile, $this->logFile);
}
public function getResolver(callable $callable, ?ReflectionFunction $reflector = null): ResolverInterface
{
$resolver = parent::getResolver($callable, $reflector);
return new Resolver($resolver);
}
}