Skip to content

Commit

Permalink
Add pool sharing example
Browse files Browse the repository at this point in the history
Relates to #367.
  • Loading branch information
kelunik committed Nov 20, 2024
1 parent d0383fa commit 7580dc2
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions examples/pooling/3-pool-share.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php declare(strict_types=1);

use Amp\CancelledException;
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 {
$pool = new UnlimitedConnectionPool();

$clientA = (new HttpClientBuilder)
->usingPool($pool)
->followRedirects(0) // no follow
->retry(3)
->build();

$clientB = (new HttpClientBuilder)
->usingPool($pool)
->followRedirects() // follow
->retry(3)
->build();

$responseA = $clientA->request(new Request($argv[1] ?? 'https://httpbin.org/redirect-to?url=%2f'));
$responseB = $clientB->request(new Request($argv[1] ?? 'https://httpbin.org/redirect-to?url=%2f'));

dumpResponseTrace($responseA);
dumpResponseTrace($responseB);
} catch (HttpException|CancelledException $error) {
echo $error;
}

0 comments on commit 7580dc2

Please sign in to comment.