enterprise-search-php
enterprise-search-php copied to clipboard
No PSR-18 clients found. Make sure to install a package providing "psr/http-client-implementation"
Summary of problem or feature request
We've upgraded our Dev Elastic deployment to 8.4 and in the process of looking at whether our service implementation needs an update.
Looking through the documentation it appears not but I'm getting
Http\Discovery\Exception\NotFoundException: No PSR-18 clients found. Make sure to install a package providing "psr/http-client-implementation". Example: "php-http/guzzle7-adapter". in Http\Discovery\Psr18ClientDiscovery::find() (line 27 of /var/www/html/vendor/php-http/discovery/src/Psr18ClientDiscovery.php).
There seems to be no mention of this in the App Search docs. I even installed with dependencies.
Code snippet of problem
protected function connect(): void {
$elastic_client = new Client([
'host' => $this->getApplicationHost(),
'app-search' => [
'token' => $this->getApiToken(),
],
]);
$this->appSearch = $elastic_client->appSearch();
}
System details
- PHP Version 8.0
- ES-PHP client version 8.4
- Elasticsearch version 8.4
Take a look at this page and see if one of the following packages meets your needs. https://docs.php-http.org/en/latest/clients.html
I ran into this as well and I already have Guzzle6 installed as a required so I added "php-http/guzzle6-adapter" to my project and it got me past that error.
Thanks @chrisryan for the support. @M-Brico did you try the suggestion? Thanks.
Cheers. I added php-http/guzzle7-adapter
in the end but shouldn't this be in the docs or as a dependency?
@M-Brico , @chrisryan I propose the PR #29 to fix issue related to the autodiscovery of HTTP client using Guzzle as default adapter.
My concern with the proposed solution is that I am using Guzzle 6 currently and having Guzzle 7 as a required package means it will conflict on composer install.
I like the flexibility of the current implementation. I believe as suggested in the original post that you just need to add something to the README.md to let people know about the extra requires and suggest a default. If you want to let composer do something similar you can use https://getcomposer.org/doc/04-schema.md#suggest.
Thanks @chrisryan for the feedback. My first intention was to give flexibility to the developers to use any PSR-18 client libraries. Of course, there some some edge cases but I think also the documentation and composer suggest can help on this.
@chrisryan I just sent PR #32 for adding a README section and also a suggest
in composer.
@ezimuel Those updates make sense to me. Thank you for making them.