- PHP Client: other versions:
- Overview
- Quickstart
- Installation
- Configuration
- Inline Host Configuration
- Extended Host Configuration
- Authorization and Encryption
- Set retries
- Enabling the Logger
- Configure the HTTP Handler
- Setting the Connection Pool
- Setting the Connection Selector
- Setting the Serializer
- Setting a custom ConnectionFactory
- Set the Endpoint closure
- Building the client from a configuration hash
- Per-request configuration
- Future Mode
- Dealing with JSON Arrays and Objects in PHP
- Index Management Operations
- Indexing Documents
- Getting Documents
- Updating Documents
- Deleting documents
- Search Operations
- Namespaces
- Security
- Connection Pool
- Selectors
- Serializers
- PHP Version Requirement
- Breaking changes from 2.x
- Community DSLs
- Community Integrations
- Reference - Endpoints
- Elasticsearch\Client
- Elasticsearch\ClientBuilder
- Elasticsearch\Namespaces\CatNamespace
- Elasticsearch\Namespaces\ClusterNamespace
- Elasticsearch\Namespaces\IndicesNamespace
- Elasticsearch\Namespaces\IngestNamespace
- Elasticsearch\Namespaces\NodesNamespace
- Elasticsearch\Namespaces\SnapshotNamespace
- Elasticsearch\Namespaces\TasksNamespace
Extended Host Configuration
editExtended Host Configuration
editThe client also supports an extended host configuration syntax. The inline configuration method relies on PHP’s
filter_var()
and parse_url()
methods to validate and extract the components of a URL. Unfortunately, these built-in
methods run into problems with certain edge-cases. For example, filter_var()
will not accept URL’s that have underscores
(which are questionably legal, depending on how you interpret the RFCs). Similarly, parse_url()
will choke if a
Basic Auth’s password contains special characters such as a pound sign (#
) or question-marks (?
).
For this reason, the client supports an extended host syntax which provides greater control over host initialization. None of the components are validated, so edge-cases like underscores in domain names will not cause problems.
The extended syntax is an array of parameters for each host:
$hosts = [ // This is effectively equal to: "https://username:password!#$?*abc@foo.com:9200/" [ 'host' => 'foo.com', 'port' => '9200', 'scheme' => 'https', 'user' => 'username', 'pass' => 'password!#$?*abc' ], // This is equal to "http://localhost:9200/" [ 'host' => 'localhost', // Only host is required ] ]; $client = ClientBuilder::create() // Instantiate a new ClientBuilder ->setHosts($hosts) // Set the hosts ->build(); // Build the client object
Only the host
parameter is required for each configured host. If not provided, the default port is 9200
. The default
scheme is http
.