I am sending multiple async promises with a guzzle timeout set to 30, I am wondering how to capture if any promises timed out so that I can report on this error. Please see the code below. Essentially I want to use any responses I can before timeout and capture those that do timeout.
foreach ($apiRequests as $guzzleParameters) {
$request = new Request($guzzleParameters->getType(), $guzzleParameters->getApiEndpoint(), $guzzleParameters->getHeaders(), $guzzleParameters->getBody());
$promises[$guzzleParameters->createKey()] = $this->client->sendAsync($request)->then(
function (ResponseInterface $res) {
return $res;
},
function (RequestException $e) {
switch ($e->getCode()) {
case 400:
// log error
break;
case 401:
// log error
break;
case 403:
// log error
break;
case 404:
// log error
break;
}
return $e->getResponse();
}
);
}
$responses = Promise\Utils::settle($promises)->wait(true);