Conditions | 3 |
Paths | 3 |
Total Lines | 30 |
Code Lines | 16 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
31 | public static function assign(string $host, int $port, array $headers, HOptions $options = null) : Client |
||
32 | { |
||
33 | $pk = "{$host}:{$port}"; |
||
34 | |||
35 | if (isset(self::$keeps[$pk])) { |
||
36 | return self::$keeps[$pk]; |
||
37 | } |
||
38 | |||
39 | $hsl = array_change_key_case($headers, CASE_LOWER); |
||
40 | |||
41 | if (strtolower($hsl['connection'] ?? '') === 'keep-alive') { |
||
42 | self::$keeps[$pk] = $cli = new Client( |
||
43 | ($options ?? (new HOptions)->setTimeouts()) |
||
44 | ->keepalive( |
||
45 | new POptions(1, 128, 4, 0, 55, 15, 0, 2000, 1000), |
||
46 | sprintf('http:%s:%d', $host, $port) |
||
47 | ), |
||
48 | new Address($host, $port) |
||
49 | ); |
||
50 | |||
51 | $cli->keepalived(static function (Pool $pool) use ($pk) { |
||
52 | $pool->closed()->then(function () use ($pk) { |
||
53 | unset(self::$keeps[$pk]); |
||
54 | }); |
||
55 | }); |
||
56 | |||
57 | return $cli; |
||
58 | } |
||
59 | |||
60 | return new Client($options ?? new HOptions); |
||
61 | } |
||
63 |