The API client methods accept additional parameters for adding headers or query parameters, or for changing the default timeouts for individual requests.

To customize all requests, you can customize the client.

For example:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
<?php

require_once realpath(__DIR__.'/vendor/autoload.php');

use Algolia\AlgoliaSearch\Api\SearchClient;
use Algolia\AlgoliaSearch\RequestOptions\RequestOptions;

$client = SearchClient::create(
    appId: 'ALGOLIA_APPLICATION_ID',
    apiKey: 'ALGOLIA_API_KEY',
);

$requestOptions = new RequestOptions;
// Add custom HTTP header to this request
$requestOptions.addHeader('extra-header', 'greetings');
// Add query parameter to this request
$requestOptions.addQueryParameter('queryParam', 'value');
// Adjust timeout for this request
$requestOptions.setReadTimeout(100);

$client->searchSingleIndex(
    indexName: 'ALGOLIA_INDEX_NAME',
    searchParams: ['query' => 'time'],
    requestOptions: $requestOptions,
);

Reference

headers
type: array<string,string>

Additional headers as key-value pairs to send with this request. To add a header, use the RequestOptions->addHeader method.

queryParameters
type: array<string,any>

Additional query parameters to send with this request. They only take effect with API operations that support query parameters. Otherwise, they’re ignored. To add query parameters to this request, use the RequestOptions->addQueryParameter method.

connectTimeout
type: int
default: 2

Maximum number of seconds to wait for the connection to be established. Use the RequestOptions->setConnectTimeout method to change this timeout.

readTimeout
type: int
default: 5

Maximum number of seconds to wait for a response from the server (for GET requests). Use the RequestOptions->setReadTimeout method to change this timeout.

writeTimeout
type: int
default: 30

Maximum number of seconds to wait for a response from the server (for requests other than GET). Use the RequestOptions->setWriteTimeout method to change this timeout.

Did you find this page helpful?
PHP API clients v4