getAsync($uri . http_build_query(['i' => $i, 's' => random_int(1, 5)])); }; } }; Lib\printf('pool'); $pool = new Pool($client, $requests(3), [ 'concurrency' => 5, 'fulfilled' => function ($response, $index) { Lib\printf(' i='. $index .' '. $response->getBody()); }, 'rejected' => function ($reason, $index) { Lib\printf(' '. $index .' '. $reason); }, ]); Lib\printf('promise'); // Initiate the transfers and create a promise $promise = $pool->promise(); Lib\printf('wait'); // Force the pool of requests to complete. $promise->wait(); Lib\printf('end');