Open cappadaan opened 1 year ago
This is similar to issue https://github.com/elastic/elasticsearch-php/issues/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.
@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.
@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
.
@gjuric I provided a fix in #1344. @cappadaan can you try this change and let me know if this fix the issue? Thanks!
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.
This issue still exists in Release 8.9.0
@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
.
psr/http-message 2.0 Common interface for HTTP messages
@cappadaan how did you install the new elasticsearch-php
8.9.0? Did you use composer update
?
@cappadaan can you paste the composer info
output? Thanks!
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?
@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.
@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:
Let me know, thanks!
thx, so far this solution seems to work.
This fatal error occurred again using 8.9.0.
I will for now downgrade to 8.8.0.
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()
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)
"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.
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.
Any ideas how to debug this? Or where to start? Could this be a bug?