1 | <?php declare(strict_types=1); |
||
11 | final class LogglyBulkLogger extends AbstractLogglyLogger |
||
12 | { |
||
13 | const LF = "\r\n"; |
||
14 | const MAX_BODY_LENGTH = 5242880; |
||
15 | const MAX_LINE_LENGTH = 1048576; |
||
16 | |||
17 | /** |
||
18 | * @var LoopInterface |
||
19 | */ |
||
20 | private $loop; |
||
21 | |||
22 | /** |
||
23 | * @var Client |
||
24 | */ |
||
25 | private $httpClient; |
||
26 | |||
27 | /** |
||
28 | * @var string |
||
29 | */ |
||
30 | private $token; |
||
31 | |||
32 | /** |
||
33 | * @var float |
||
34 | */ |
||
35 | private $timeout; |
||
36 | |||
37 | /** |
||
38 | * @var string[] |
||
39 | */ |
||
40 | private $buffer = []; |
||
41 | |||
42 | /** |
||
43 | * @var int |
||
44 | */ |
||
45 | private $bufferSize = 0; |
||
46 | |||
47 | /** |
||
48 | * @var TimerInterface |
||
49 | */ |
||
50 | private $timer; |
||
51 | |||
52 | public static function create(LoopInterface $loop, string $token, float $timeout = 5.3): self |
||
53 | { |
||
54 | $resolverFactory = new ResolverFactory(); |
||
55 | $resolver = $resolverFactory->createCached('8.8.8.8', $loop); |
||
56 | |||
57 | $factory = new HttpClientFactory(); |
||
58 | $httpClient = $factory->create($loop, $resolver); |
||
59 | |||
60 | return new self($loop, $httpClient, $token, $timeout); |
||
61 | } |
||
62 | |||
63 | 12 | public static function createFromHttpClient( |
|
71 | |||
72 | 12 | private function __construct(LoopInterface $loop, Client $httpClient, string $token, float $timeout) |
|
79 | |||
80 | 12 | protected function send(string $data) |
|
95 | |||
96 | 12 | private function ensureTimer() |
|
107 | |||
108 | 12 | private function sendBulk() |
|
130 | } |
||
131 |