Search code examples
elasticsearchhttpclientguzzle

Elastic Cloud PHP Connection error: I did not find any HTTP library with HttpAsyncClient interface


When connecting to Elastic Cloud Im constantly running into this weird error:

Fatal error: Uncaught Elastic\Transport\Exception\NoAsyncClientException: I did not find any HTTP library with HttpAsyncClient interface. Make sure to install a package providing "php-http/async-client-implementation". You can also set a specific async library using Elastic\Transport\Transport::setAsyncClient()

I have tried everything the internet offers in terms of setting http clients, composer Guzzle etc... But to no avail. I also tested it on one of our live servers and the error is there too.

My code:

$httpClient = new GuzzleHttp\Client();
$client = ClientBuilder::create()
    ->setHttpClient($httpClient)
    ->setElasticCloudId('xxxxxxxxxxxxxxxxxxxx')
    ->setBasicAuthentication('xxxxxxxxx', 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx')
    ->build();

Composer

{
"require": {
    "elasticsearch/elasticsearch": "^8.6",
    "php-http/async-client-implementation": "*",
    "guzzlehttp/guzzle": "^7.5"
},
"config": {
    "allow-plugins": {
        "php-http/discovery": true
    }
}

}


Solution

  • disclaimer: I'm not a php dev either

    You should require a concrete asynch adapter/implementation for those client libraries that are not PSR-18 compliant, like

    "require": {
        "elasticsearch/elasticsearch": "^8.6",
        "php-http/async-client-implementation": "*",
        "guzzlehttp/guzzle": "^7.5",
        "php-http/guzzle7-adapter": "*"            <----------
    }