Elastic Cloud PHP连接错误:我没有找到任何具有HttpAsyncClient接口的HTTP库。

huangapple go评论62阅读模式
英文:

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&#39;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

&quot;require&quot;: {
    &quot;elasticsearch/elasticsearch&quot;: &quot;^8.6&quot;,
    &quot;php-http/async-client-implementation&quot;: &quot;*&quot;,
    &quot;guzzlehttp/guzzle&quot;: &quot;^7.5&quot;,
    &quot;php-http/guzzle7-adapter&quot;: &quot;*&quot;            &lt;----------
}

答案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&#39;m not a php dev,

but, according to the docs,
> You can enable the HTTP async in elasticsearch-php using the setAsync() function

huangapple
  • 本文由 发表于 2023年2月26日 22:58:51
  • 转载请务必保留本文链接:https://go.coder-hub.com/75572831.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定