Configuring timeouts

Required API Key: no ACL required
Method signature
$client->setConnectTimeout(connectTimeout, readTimeout, searchReadTimeout)
Method signature
Algolia.init({
  application_id: 'YourApplicationId',
  api_key: 'YourApiKey',
  connect_timeout: connectTimeout,
  send_timeout: requestTimeout,
  receive_timeout: readTimeout,
  batch_timeout: searchBatchTimeout,
  search_timeout: searchReadTimeout
})

Method signature
client.setTimeouts({
  connect: connectTimeout,
  read: readTimeout,
  write: writeTimeout
})

Method signature
client.search_timeout = (connectTimeout, searchReadTimeout)
client.timeout = (connectTimeout, readTimeout)
Method signature
client.timeout = readTimeout
client.searchTimeout = requestTimeout
Method signature
client.setConnectTimeout(connectTimeout)
client.setReadTimeout(readTimeout)
client.setSearchTimeout(requestTimeout)
client.setHostDownDelay(hostDownDelay)
Method signature
client.setTimeout(readTimeout, writeTimeout)
client._dsnInternalTimeout = dnsTimeout
Method signature
new ApacheAPIClientBuilder(...)
  .setConnectTimeout(connectTimeout)
  .setReadTimeout(readTimeout)
  .setHostDownTimeout(hostDownDelay)

new AppEngineAPIClientBuilder(...)
  .setConnectTimeout(connectTimeout)
  .setReadTimeout(readTimeout)
  .setHostDownTimeout(hostDownDelay)

new AsyncHttpAPIClientBuilder(...)
  .setConnectTimeout(connectTimeout)
  .setReadTimeout(readTimeout)
  .setHostDownTimeout(hostDownDelay)

Method signature
client.SetTimeout(connectTimeout, readTimeout)
Method signature
AlgoliaClientConfiguration(
  httpConnectTimeoutMs = connectTimeout,
  httpReadTimeoutMs = readTimeout,
  httpRequestTimeoutMs = requestTimeout,
  dnsTimeoutMs = dnsTimeout,
  hostDownTimeoutMs = hostDownDelay
)

About this method

Override the pre-configured timeouts.

Network & DNS resolution can be slow. That is why we have pre-configured timeouts. We do not advise to change them, but it could make sense to change them in some special cases.

Note: Not all parameters are available for every language. See Parameters below.

Examples

<?php
$client = new \AlgoliaSearch\Client('YourApplicationID', 'YourAdminAPIKey');
$client->setConnectTimeout(
  2, // the connection timeout
  30, // the read timeout for the query
  5 // the read timeout used for search queries only
);
Algolia.init({
  application_id: 'YourApplicationId',
  api_key: 'YourApiKey',
  connect_timeout: 2,
  send_timeout: 30,
  receive_timeout: 30,
  batch_timeout: 120,  # send_timeout override for batches
  search_timeout: 5    # send_timeout override for queries
})
// at init time:
var client = algoliasearch(appId, apiKey, {
  timeouts: {
    connect: 1000,
    read: 2 * 1000,
    write: 30 * 1000
  }
});

// after initialization:
client.setTimeouts({
  connect: 1000,
  read: 2 * 1000,
  write: 30 * 1000
});

// timers in JavaScript are specified in milliseconds
client = algoliasearch.Client(...)
client.search_timeout = (1, 5) # Connection and read timeout for search operations
client.timeout = (1, 30) # Connection and read timeout for other operations
// Time-out for search queries:
client.searchTimeout = 5.0 // in seconds
// Time-out for other requests:
client.timeout = 10.0 // in seconds
  APIClient client = new ApiClient(...);
  client.setConnectTimeout(2000); // connection timeout
  client.setReadTimeout(30000); // read timeout
  client.setSearchTimeout(5000) // read timeout for search requests
  client.setHostDownDelay(5000); // delay before retrying a host we know was down
  AlgoliaClient client = new AlgoliaClient(...);
  client.setTimeout(
    4000, /* readTimeout */
    4000, /* writeTimeout */
  );
  client._dsnInternalTimeout = 4000 // delay before retrying a host we know was down
// Sync version
new ApacheAPIClientBuilder(...)
  .setConnectTimeout(4000)
  .setReadTimeout(4000)
  .setHostDownTimeout(4000);

new AppEngineAPIClientBuilder(...)
  .setConnectTimeout(4000)
  .setReadTimeout(4000)
  .setHostDownTimeout(4000);

// Async version
new AsyncHttpAPIClientBuilder(...)
  .setConnectTimeout(4000)
  .setReadTimeout(4000)
  .setHostDownTimeout(4000);
  client := algoliasearch.NewClient(...)
  connectTimeoutMs := 3000
  readTimeoutMs := 60000
  client.SetTimeout(connectTimeoutMs, readTimeoutMs)
val configuration = AlgoliaClientConfiguration(
  httpConnectTimeoutMs = 2 * 1000,
  httpReadTimeoutMs = 2 * 1000,
  httpRequestTimeoutMs = 2 * 1000,
  dnsTimeoutMs = 2 * 100,
  hostDownTimeoutMs = 5 * 60 * 1000
)
new AlgoliaClient(applicationId, apiKey, configuration = configuration)

Parameters

connectTimeout
type: integer
Optional
default:

Timeout for the tcp session to connect.

Only available for the following languages: javascript, php, python, ruby, java, android, go, scala.

readTimeout
type: integer
Optional
default:

Timeout for the read on the tcp socket.

Available in all languages.

writeTimeout
type: integer
Optional
default:

Same as requestTimeout but applies only to write operations.

Only available for the following languages: javascript, csharp.

hostDownDelay
type: integer
Optional
default:

The expected period of time for a down host to get back up again. Impacts the time between API Client retries.

Only available for the following languages: java, android, scala.

dnsTimeout
type: integer
Optional
default:

Timeout for the dns resolution.

Only available for the following languages: csharp, scala.

searchBatchTimeout
type: integer
Optional
default:

Same as requestTimeout but applies only to batch operations.

Only available for the following language: ruby.

searchReadTimeout
type: integer
Optional
default:

Same as requestTimeout but applies only to search operations.

Only available for the following languages: php, python, ruby.

requestTimeout
type: integer
Optional
default:

Http timeout for the request.

Only available for the following languages: ruby, android, swift, scala.

Response

No response
Php small white
PHP
Ruby small white
Ruby
Javascript small white
JavaScript
Python small white
Python
Swift small white
iOS
Android small white
Android
Csharp small white
C#
Java small white
Java
Go small white
Go
Scala small white
Scala
Php small white
PHP
Ruby small white
Ruby
Javascript small white
JavaScript
Python small white
Python
Swift small white
iOS
Android small white
Android
Csharp small white
C#
Java small white
Java
Go small white
Go
Scala small white
Scala