enterprise-search-php icon indicating copy to clipboard operation
enterprise-search-php copied to clipboard

No PSR-18 clients found. Make sure to install a package providing "psr/http-client-implementation"

Open M-Brico opened this issue 1 year ago • 8 comments

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

M-Brico avatar Sep 15 '22 11:09 M-Brico

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.

chrisryan avatar Sep 16 '22 20:09 chrisryan

Thanks @chrisryan for the support. @M-Brico did you try the suggestion? Thanks.

ezimuel avatar Sep 21 '22 07:09 ezimuel

Cheers. I added php-http/guzzle7-adapter in the end but shouldn't this be in the docs or as a dependency?

M-Brico avatar Sep 21 '22 14:09 M-Brico

@M-Brico , @chrisryan I propose the PR #29 to fix issue related to the autodiscovery of HTTP client using Guzzle as default adapter.

ezimuel avatar Oct 11 '22 07:10 ezimuel

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.

chrisryan avatar Oct 11 '22 12:10 chrisryan

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.

ezimuel avatar Oct 11 '22 12:10 ezimuel

@chrisryan I just sent PR #32 for adding a README section and also a suggest in composer.

ezimuel avatar Oct 19 '22 08:10 ezimuel

@ezimuel Those updates make sense to me. Thank you for making them.

chrisryan avatar Oct 24 '22 13:10 chrisryan