-
-
Notifications
You must be signed in to change notification settings - Fork 67
/
1-connection-count.php
34 lines (25 loc) · 1.19 KB
/
1-connection-count.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
<?php declare(strict_types=1);
use Amp\Http\Client\Connection\UnlimitedConnectionPool;
use Amp\Http\Client\HttpClientBuilder;
use Amp\Http\Client\HttpException;
use Amp\Http\Client\Request;
require __DIR__ . '/../.helper/functions.php';
try {
// There's no need to create a custom pool here, we just need it to access the statistics.
$pool = new UnlimitedConnectionPool;
$client = (new HttpClientBuilder)
->usingPool($pool)
->followRedirects(0)
->build();
$firstResponse = $client->request(new Request($argv[1] ?? 'https://httpbin.org/user-agent'));
dumpResponseTrace($firstResponse);
dumpResponseBodyPreview($firstResponse->getBody()->buffer());
$secondResponse = $client->request(new Request($argv[1] ?? 'https://httpbin.org/user-agent'));
dumpResponseTrace($secondResponse);
dumpResponseBodyPreview($secondResponse->getBody()->buffer());
print "Total connection attempts: " . $pool->getTotalConnectionAttempts() . "\r\n";
print "Total stream requests: " . $pool->getTotalStreamRequests() . "\r\n";
print "Currently open connections: " . $pool->getOpenConnectionCount() . "\r\n";
} catch (HttpException $error) {
echo $error;
}