PHP code example of arntech / guzzle-pool-client

1. Go to this page and download the library: Download arntech/guzzle-pool-client library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

arntech / guzzle-pool-client example snippets


$pool = new DynamicPool(100);// where 100 is the pool size

$pool = new DynamicPool(100);// where 100 is the pool size
$client = new DynamicPoolClient(['pool'=>$pool]);
//or
$client = new DynamicPoolClient(['pool_size'=>100]);// where 100 is the pool size
//or use uniqe calls for each request
$client = new DynamicUniquePoolClient(['pool_size'=>100]);
$client->add($promise, 'key');

$this->client = new DynamicPoolClient(['pool_size'=>10]);
$req1=$this->client->getAsync('http://first.url')
    ->then(function ($response) {
        //do something
        $req2=$this->client->getAsync('http://second.url')
            ->then(function ($response) {
                //do something with response
            });
        $this->client->add($req2);
    });
$this->client->add($req1);
$this->client->wait();

private function runGet($url)
{
    $this->client->add($this->client->getAsync($url), $url);
}
$this->client = new DynamicUniquePoolClient(['pool_size'=>10]);
$this->runGet('http://first.url');
$this->runGet('http://second.url');
$this->runGet('http://first.url'); //this will be canceled

$this->client->wait();