Add request options
You can change the default timeouts, or add extra HTTP headers to your API requests by passing options. These API client methods support passing request options as extra key-value mappings:
To add options to all requests, you can create a custom configuration
Add HTTP headers to your requests
Adding HTTP headers to your requests allow you to set parameters, for example, a user identifier or an IP address. This can be useful for analytics, geo search, or to implement API key rate limits.
You can add these headers to your requests:
||Use API key rate limits|
||The Analytics API uses the value of this header to distinguish between users. It takes priority over any value in
||For analytics in back-end implementations. If your server sends the user’s IP address with every search, analytics can distinguish between end users. Otherwise, the analytics uses the server’s IP address, and considers all your users as a single user.|
||For geolocation, when you perform searches from your back end. This ensures that the geolocation for a search uses the IP address of your end user, and not that of your server.|
1 2 3 4 5 $index = $client->initIndex('indexName'); $res = $index->search('query string', [ 'X-Algolia-UserToken' => 'user123' ]);
Change timeouts for your requests
Network connections and DNS resolution can be slow. That’s why the API clients come with default timeouts.
1 2 3 4 5 6 $index = $client->initIndex('indexName'); $res = $index->search('query string', [ // Set the readTimeout to 20 seconds 'readTimeout' => 20 ]);
Some methods accept extra request options. You can find them in the Parameters section for each method’s reference.