public function request($context, $method, $path, $params, $data, $hostsArray, $connectTimeout, $readTimeout)
{
$exceptions = array();
$cnt = 0;
foreach ($hostsArray as &$host) {
$cnt += 1;
if ($cnt == 3) {
$connectTimeout += 2;
$readTimeout += 10;
}
try {
$res = $this->doRequest($context, $method, $host, $path, $params, $data, $connectTimeout, $readTimeout);
if ($res !== null) {
return $res;
}
} catch (AlgoliaException $e) {
throw $e;
} catch (\Exception $e) {
$exceptions[$host] = $e->getMessage();
}
}
throw new AlgoliaException('Hosts unreachable: ' . implode(',', $exceptions));
}