英文:
Elastic Cloud PHP Connection error: I did not find any HTTP library with HttpAsyncClient interface
问题
当连接到 Elastic Cloud 时,我一直遇到这个奇怪的错误:
致命错误:未捕获 Elastic\Transport\Exception\NoAsyncClientException:找不到带有 HttpAsyncClient 接口的任何 HTTP 库。确保安装提供 "php-http/async-client-implementation" 包。您还可以使用 Elastic\Transport\Transport::setAsyncClient() 设置特定的异步库。
我尝试过互联网提供的有关设置 HTTP 客户端、composer Guzzle 等方面的所有方法... 但都没有成功。我还在我们的一个生产服务器上进行了测试,错误仍然存在。
我的代码:
$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
}
}
}
英文:
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
}
}
}
答案1
得分: 2
disclaimer: I'm not a php dev either
你应该为那些不符合PSR-18规范的客户端库,需要一个具体的异步适配器/实现,比如:
"require": {
"elasticsearch/elasticsearch": "^8.6",
"php-http/async-client-implementation": "*",
"guzzlehttp/guzzle": "^7.5",
"php-http/guzzle7-adapter": "*" <----------
}
英文:
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": "*" <----------
}
答案2
得分: 0
disclaimer: I'm not a php dev
, but, according to the docs, > You can enable the HTTP async in elasticsearch-php using the setAsync() function
英文:
disclaimer: I'm not a php dev
,
but, according to the docs,
> You can enable the HTTP async in elasticsearch-php using the setAsync() function
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论