-
Notifications
You must be signed in to change notification settings - Fork 3
/
push.php
45 lines (33 loc) · 1.31 KB
/
push.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
<?php
use Amp\Cache\LocalCache;
use Amp\Http\Client\Cache\SingleUserCache;
use Amp\Http\Client\HttpClientBuilder;
use Amp\Http\Client\Request;
use Amp\Log\ConsoleFormatter;
use Amp\Log\StreamHandler;
use Monolog\Logger;
use Monolog\Processor\PsrLogMessageProcessor;
use function Amp\ByteStream\getStdout;
use function Amp\now;
require __DIR__ . '/../vendor/autoload.php';
$logFormatter = new ConsoleFormatter;
$logFormatter->allowInlineLineBreaks();
$logFormatter->ignoreEmptyContextAndExtra();
$streamHandler = new StreamHandler(getStdout());
$streamHandler->setFormatter($logFormatter);
$logger = new Logger('main');
$logger->pushProcessor(new PsrLogMessageProcessor);
$logger->pushHandler($streamHandler);
$pushEnabled = ($argv[1] ?? '') === '--disable-push';
$cache = new SingleUserCache(new LocalCache(), $logger, storePushedResponses: $pushEnabled);
$client = (new HttpClientBuilder)
->intercept($cache)
->build();
$start = now();
$response = $client->request(new Request('https://http2-server-push-demo.keksi.io/'));
$response->getBody()->buffer();
$response = $client->request(new Request('https://http2-server-push-demo.keksi.io/image.jpg'));
$response->getBody()->buffer();
$logger->info('Took {runtime} seconds' . ($pushEnabled ? ', run with --disable-push to compare' : ''), [
'runtime' => now() - $start,
]);