Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Declaration of Elastic\Elasticsearch\Response\Elasticsearch::withStatus must be compatible #1342

Open
cappadaan opened this issue Jul 22, 2023 · 19 comments

Comments

@cappadaan
Copy link

Out of nowhere we suddenly get this fatal error popping up.
It looks random, after running the same script again, it works fine.

Declaration of Elastic\Elasticsearch\Response\Elasticsearch::withStatus(int $code, string $reasonPhrase = ''): Psr\Http\Message\ResponseInterface must be compatible with Psr\Http\Message\ResponseInterface::withStatus($code, $reasonPhrase = '')

We do not use this method (withStatus) in our code.

  • Operating System: Almalinux 9.2
  • PHP Version: 8.2
  • ES-PHP client version: 8.8.1
  • Elasticsearch version: 8.6

Any ideas how to debug this? Or where to start? Could this be a bug?

@ezimuel
Copy link
Contributor

ezimuel commented Aug 1, 2023

This is similar to issue #1327. The randomness of this issue is very strange. Can you try to downgrade to 8.8.0 to check if the error still occurs? Let me know, thanks.

@ezimuel
Copy link
Contributor

ezimuel commented Aug 1, 2023

@gjuric since we have issues due to the different interfaces of psr/http-message 2.0 vs 1.0. I'm wondering if we should change the composer.json to allow only psr/http-message: "^2.0". I'm not sure about the implication of this for the HTTP clients. WDYT? Thanks.

@ezimuel
Copy link
Contributor

ezimuel commented Aug 2, 2023

@gjuric I'm investigating and I discovered that we should require psr/http-message with ^1.1 || ^2.0 as suggested here. Right now, we are supporting ^1.0 || ^2.0. Guzzle is using this requirement and also nyholm/psr7 and symfony the same since it uses nyholm/psr7.

@ezimuel
Copy link
Contributor

ezimuel commented Aug 2, 2023

@gjuric I provided a fix in #1344. @cappadaan can you try this change and let me know if this fix the issue? Thanks!

@ezimuel
Copy link
Contributor

ezimuel commented Aug 3, 2023

I finally reproduced the issue. This error occurs when you have psr/http-message with v1.0. The issue disappears with v1.1 since it includes scalar parameter types. The PR #1344 fixes the issue.

@cappadaan
Copy link
Author

This issue still exists in Release 8.9.0

@ezimuel
Copy link
Contributor

ezimuel commented Aug 8, 2023

@cappadaan if you run composer info in the folder of your application, which version of psr/http-message you see? It should be 1.1 or 2.0.

@cappadaan
Copy link
Author

psr/http-message 2.0 Common interface for HTTP messages

@ezimuel
Copy link
Contributor

ezimuel commented Aug 8, 2023

@cappadaan how did you install the new elasticsearch-php 8.9.0? Did you use composer update?

@cappadaan
Copy link
Author

  • "elasticsearch/elasticsearch": "^8.8.0"
  • composer update
  • it did update to 8.9.0
  • the fatal error occured a few minutes later
  • then downgraded tot 8.8.0 again ("elasticsearch/elasticsearch": "8.8.0") and all was fine

@ezimuel
Copy link
Contributor

ezimuel commented Aug 8, 2023

@cappadaan can you paste the composer info output? Thanks!

@cappadaan
Copy link
Author

cappadaan commented Aug 8, 2023

elastic/transport v8.7.0 HTTP transport PHP library for Elastic products
elasticsearch/elasticsearch v8.8.0 PHP Client for Elasticsearch

psr/cache 3.0.0 Common interface for caching libraries
psr/container 2.0.2 Common Container Interface (PHP FIG PSR-11)
psr/event-dispatcher 1.0.0 Standard interfaces for event handling.
psr/http-client 1.0.2 Common interface for HTTP clients
psr/http-factory 1.0.2 Common interfaces for PSR-7 HTTP message factories
psr/http-message 1.1 Common interface for HTTP messages
psr/log 3.0.0 Common interface for logging libraries

I cannot share everything, need a specific one?

@sarpkaya-xx
Copy link

@cappadaan I was experiencing a similar error, I found the solution to use a different Http Client as mentioned at https://www.elastic.co/guide/en/elasticsearch/client/php-api/current/http-client.html#http-client.

I updated my code block as below,

use GuzzleHttp\Client as GuzzleClient;

ClientBuilder::create()
        ->setHttpClient(new GuzzleClient(['verify'=>false,
        'http_errors'=>false])
        )
        ->setHosts([env('APPLICATION_LOGS_ES_HOST')])
        ->setRetries(1)
        ->setBasicAuthentication(env('APPLICATION_LOGS_ES_USERNAME'), env('APPLICATION_LOGS_ES_PASSWORD'))
        ->build();

Error message I was getting was

Declaration of Symfony\Component\HttpClient\CurlHttpClient::stream(Symfony\Contracts\HttpClient\ResponseInterface|Traversable|array $responses, ?float $timeout = null): Symfony\Contracts\HttpClient\ResponseStreamInterface must be compatible with Symfony\Contracts\HttpClient\HttpClientInterface::stream($responses, ?float $timeout = null): Symfony\Contracts\HttpClient\ResponseStreamInterface

Hope this solution has something to do with your problem.

@ezimuel
Copy link
Contributor

ezimuel commented Aug 9, 2023

@cappadaan I'm trying to reproduce the issue but I failed. Can you try to have a clean installation using "elasticsearch/elasticsearch": "^8.9.0" in composer.json? After updating the 8.9.0 dependency in composer, you can try the following commands:

  • composer clearcache
  • rm -rf vendor/
  • rm composer.lock
  • composer install

Let me know, thanks!

@cappadaan
Copy link
Author

thx, so far this solution seems to work.

@cappadaan
Copy link
Author

This fatal error occurred again using 8.9.0.

I will for now downgrade to 8.8.0.

@cappadaan
Copy link
Author

I ran into the same issue on 8.8.0 now, but this is the first in a long time:

PHP Fatal error: Declaration of Elastic\Elasticsearch\Response\Elasticsearch::getStatusCode() must be compatible with Psr\Http\Message\ResponseInterface::getStatusCode()

@hakanguner
Copy link

Similar issue has occurred for us as well. We installed Elasticsearch version 8.10.0. I installed ES-PHP client 8.9.0. After that I downgraded to Elasticsearch version 8.8.0 and ES-PHP client 8.8.1 but the problem continues.

Fatal error: Declaration of Elastic\Elasticsearch\Response\Elasticsearch::withStatus(int $code, string $reasonPhrase = ''): Psr\Http\Message\ResponseInterface must be compatible with PsrExt\Http\Message\ResponseInterface::withStatus($code, $reasonPhrase = NULL)

@skycccu
Copy link

skycccu commented Oct 27, 2023

"elasticsearch/elasticsearch" required "psr/http-message": "^1.0 || ^2.0"
"guzzlehttp/psr7" required "psr/http-message": "^1.0"
"psr/http-client" rquired "psr/http-message": "^1.0"

I tried to update psr/http-message:^1.1 to psr/http-message:^1.0.1 version, and the project returned to normal.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants