The Typesense PHP client is initialized using a configuration array passed to the Configuration constructor. The configuration defines connection nodes, authentication, retry logic, logging, and the HTTP client.
Required Keys
nodes: An array of node dictionaries. Each node must contain host, port, and protocol.api_key: Your Typesense API key.
Optional Keys
randomize_nodes: Boolean. If true (default), the order of nodes is shuffled to distribute load.nearest_node: A dictionary defining a specific node to prioritize.healthcheck_interval_seconds: Integer. Interval for health checks (default: 60).num_retries: Float. Number of retries for failed requests (default: 3.0).retry_interval_seconds: Float. Seconds to wait between retries (default: 1.0).logger: An object implementing Psr\Log\\LoggerInterface. If provided, you cannot set log_level.log_level: The logging level (e.g., using Monolog constants) if no custom logger is provided.client: An HTTP client. Supports Psr\\Http\\Client\\ClientInterface, Http\\Client\\HttpClient, or Http\\Client\\Common\\HttpMethodsClient.
$config = [
'nodes' => [
[
'host' => 'localhost',
'port' => 8108,
'protocol' => 'http',
'path' => '',
],
],
'api_key' => 'your_api_key',
'num_retries' => 5.0,
'retry_interval_seconds' => 2.0,
'randomize_nodes' => true,
];
$configuration = new \Typesense\Lib\Configuration($config);