Skip to content

fix(php): support guzzlehttp/psr7 v3 - #6945

Merged
eric-zaharia merged 7 commits into
mainfrom
fix/php-psr7-v3
Aug 25, 2026
Merged

eric-zaharia merged 7 commits into
mainfrom
fix/php-psr7-v3

Conversation

@eric-zaharia

@eric-zaharia eric-zaharia commented Aug 24, 2026 •

Copy link
Copy Markdown
Contributor

🧭 What and Why

🎟 JIRA Ticket: API-551

composer require algolia/algoliasearch-client-php fails on modern Laravel apps, which lock guzzlehttp/psr7 to ^3.0.

Fixes algolia/algoliasearch-client-php#762.

Changes included:

  • Widen the PHP client's guzzlehttp/psr7 constraint to ^2.0 || ^3.0.
  • Handle guzzle 8 in GuzzleHttpClient. psr7 ^3.0 makes guzzle 8 installable alongside the client for the first time, and guzzle 8 reclassified transfer failures four ways:
    • No-response failures moved out of ConnectException into a new NetworkException family, so they escaped both catch arms and bypassed the host retry loop entirely. Catch the PSR-18 NetworkExceptionInterface that both majors tag those failures with.
    • Read timeouts that land after response headers arrive throw ResponseTimeoutException, which extends RequestException and carries a non-nullable response, so the truncated response was returned as a success: a partial body surfaced as a DeserializationException that the retry loop rethrows without failing over, and an empty body returned null as a successful result. Catch it alongside NetworkExceptionInterface, restoring guzzle 7's behaviour of raising TimeoutException and retrying. The class does not exist in guzzle 7, where the arm is inert.
    • RequestException::hasResponse() was dropped, which fataled the response branch. Probe for getResponse() instead, which also maps cleanly onto guzzle 8's ResponseException split.
    • A handler closed mid-transfer throws the new HandlerClosedException, which hangs off TransferException directly and so matched neither arm — it escaped the retry loop as a raw guzzle exception. Catch it alongside the network failures. Also guzzle-8-only, so the arm is inert on guzzle 7.
  • Refresh composer.lock for the widened range.

🧪 Test

CTS passes against psr7 3.0.0. GuzzleHttpClient verified against real installs of guzzle 8.1.0 / psr7 3.1.0 and guzzle 7.15.5 / psr7 2.13.1, driving the client against a fault-injection server. Both majors agree on every tested scenario: read timeouts (with a partial body and with none) and connection refused raise TimeoutException and retry across hosts, 2xx and 5xx return the response, and an early connection close returns the partial response — matching guzzle 7's long-standing behaviour, which is byte-identical before and after this PR.

Guzzle 8 does classify more low-level curl errors as network failures than guzzle 7's ConnectException did, so a few outside those scenarios — a connection reset before headers, say — now take the TimeoutException retry path rather than the status-0 one. Both fail over and both exhaust into UnreachableException.

@eric-zaharia eric-zaharia self-assigned this Aug 24, 2026
@algolia-api-clients-automation-bot

algolia-api-clients-automation-bot Bot commented Aug 24, 2026 •

Copy link
Copy Markdown
Contributor

✔️ Code generated!

Name Link
🪓 Triggered by f076f6ca418f7e7965868639fddbc68577cdd0b8
🍃 Generated commit d00b6b0da9facece46fb431852fe48ac58ede6c1
🌲 Generated branch generated/fix/php-psr7-v3
📊 Benchmark results

Benchmarks performed on the method using a mock server, the results might not reflect the real-world performance.

Language Req/s
javascript 2190
go 1809
php 1647
csharp 1499
python 1359
java 1100
ruby 881
scala 758
swift 580

@aikido-pr-checks

aikido-pr-checks Bot commented Aug 24, 2026 •

Copy link
Copy Markdown

Summary by Aikido

Security Issues: 0 Quality Issues: 0 Resolved Issues: 0

⚡ Enhancements

  • Widened PSR-7 compatibility and added Guzzle seven/eight development coverage
  • Updated PHP CTS execution with the required test bootstrap

🐛 Bugfixes

  • Fixed Guzzle eight timeout and network failures bypassing retries

More info

Allowing guzzlehttp/psr7 ^3.0 makes guzzlehttp/guzzle 8 installable
alongside the client for the first time, and Algolia::getHttpClient()
selects GuzzleHttpClient for any major >= 6.

Guzzle 8 moved no-response failures out of ConnectException into a new
NetworkException family, so read timeouts and resets escaped both catch
arms and bypassed the host retry loop. Catch the PSR-18
NetworkExceptionInterface instead, which both majors tag those failures
with. Guzzle 8 also dropped RequestException::hasResponse(), which
fataled the response branch.

Also refresh composer.lock for the widened psr7 range.
Guzzle 8 splits read timeouts by whether response headers already
arrived. Without a response it throws NetworkTimeoutException, but once
headers are in it throws ResponseTimeoutException, which extends
RequestException and always carries a response -- so the
NetworkExceptionInterface arm missed it and the truncated response was
returned as a success. A partial body then surfaced as a
DeserializationException that the retry loop rethrows without failing
over, and an empty body returned null as a successful result.

Guzzle 7 raised ConnectException here and retried, so catch
ResponseTimeoutException alongside NetworkExceptionInterface. The class
does not exist in guzzle 7, where the arm is inert.
@eric-zaharia
eric-zaharia marked this pull request as ready for review August 25, 2026 13:39
@eric-zaharia
eric-zaharia requested a review from a team as a code owner August 25, 2026 13:39
@eric-zaharia
eric-zaharia enabled auto-merge (squash) August 25, 2026 14:30
@eric-zaharia
eric-zaharia merged commit 28aa13d into main Aug 25, 2026
38 checks passed
@eric-zaharia
eric-zaharia deleted the fix/php-psr7-v3 branch August 25, 2026 14:38
algolia-api-clients-automation-bot Bot added a commit that referenced this pull request Aug 25, 2026
Co-authored-by: Eric Zaharia <94015633+eric-zaharia@users.noreply.github.com>
algolia-api-clients-automation-bot Bot added a commit to algolia/algoliasearch-client-csharp that referenced this pull request Aug 25, 2026
algolia/api-clients-automation#6945

Co-authored-by: algolia-api-clients-automation-bot[bot] <288895823+algolia-api-clients-automation-bot[bot]@users.noreply.github.com>
Co-authored-by: Eric Zaharia <94015633+eric-zaharia@users.noreply.github.com>
algolia-api-clients-automation-bot Bot added a commit to algolia/algoliasearch-client-dart that referenced this pull request Aug 25, 2026
algolia/api-clients-automation#6945

Co-authored-by: algolia-api-clients-automation-bot[bot] <288895823+algolia-api-clients-automation-bot[bot]@users.noreply.github.com>
Co-authored-by: Eric Zaharia <94015633+eric-zaharia@users.noreply.github.com>
algolia-api-clients-automation-bot Bot added a commit to algolia/algoliasearch-client-go that referenced this pull request Aug 25, 2026
algolia/api-clients-automation#6945

Co-authored-by: algolia-api-clients-automation-bot[bot] <288895823+algolia-api-clients-automation-bot[bot]@users.noreply.github.com>
Co-authored-by: Eric Zaharia <94015633+eric-zaharia@users.noreply.github.com>
algolia-api-clients-automation-bot Bot added a commit to algolia/algoliasearch-client-java that referenced this pull request Aug 25, 2026
algolia/api-clients-automation#6945

Co-authored-by: algolia-api-clients-automation-bot[bot] <288895823+algolia-api-clients-automation-bot[bot]@users.noreply.github.com>
Co-authored-by: Eric Zaharia <94015633+eric-zaharia@users.noreply.github.com>
algolia-api-clients-automation-bot Bot added a commit to algolia/algoliasearch-client-javascript that referenced this pull request Aug 25, 2026
algolia/api-clients-automation#6945

Co-authored-by: algolia-api-clients-automation-bot[bot] <288895823+algolia-api-clients-automation-bot[bot]@users.noreply.github.com>
Co-authored-by: Eric Zaharia <94015633+eric-zaharia@users.noreply.github.com>
algolia-api-clients-automation-bot Bot added a commit to algolia/algoliasearch-client-kotlin that referenced this pull request Aug 25, 2026
algolia/api-clients-automation#6945

Co-authored-by: algolia-api-clients-automation-bot[bot] <288895823+algolia-api-clients-automation-bot[bot]@users.noreply.github.com>
Co-authored-by: Eric Zaharia <94015633+eric-zaharia@users.noreply.github.com>
algolia-api-clients-automation-bot Bot added a commit to algolia/algoliasearch-client-php that referenced this pull request Aug 25, 2026
algolia/api-clients-automation#6945

Co-authored-by: algolia-api-clients-automation-bot[bot] <288895823+algolia-api-clients-automation-bot[bot]@users.noreply.github.com>
Co-authored-by: Eric Zaharia <94015633+eric-zaharia@users.noreply.github.com>
algolia-api-clients-automation-bot Bot added a commit to algolia/algoliasearch-client-python that referenced this pull request Aug 25, 2026
algolia/api-clients-automation#6945

Co-authored-by: algolia-api-clients-automation-bot[bot] <288895823+algolia-api-clients-automation-bot[bot]@users.noreply.github.com>
Co-authored-by: Eric Zaharia <94015633+eric-zaharia@users.noreply.github.com>
algolia-api-clients-automation-bot Bot added a commit to algolia/algoliasearch-client-ruby that referenced this pull request Aug 25, 2026
algolia/api-clients-automation#6945

Co-authored-by: algolia-api-clients-automation-bot[bot] <288895823+algolia-api-clients-automation-bot[bot]@users.noreply.github.com>
Co-authored-by: Eric Zaharia <94015633+eric-zaharia@users.noreply.github.com>
algolia-api-clients-automation-bot Bot added a commit to algolia/algoliasearch-client-scala that referenced this pull request Aug 25, 2026
algolia/api-clients-automation#6945

Co-authored-by: algolia-api-clients-automation-bot[bot] <288895823+algolia-api-clients-automation-bot[bot]@users.noreply.github.com>
Co-authored-by: Eric Zaharia <94015633+eric-zaharia@users.noreply.github.com>
algolia-api-clients-automation-bot Bot added a commit to algolia/algoliasearch-client-swift that referenced this pull request Aug 25, 2026
algolia/api-clients-automation#6945

Co-authored-by: algolia-api-clients-automation-bot[bot] <288895823+algolia-api-clients-automation-bot[bot]@users.noreply.github.com>
Co-authored-by: Eric Zaharia <94015633+eric-zaharia@users.noreply.github.com>
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

Successfully merging this pull request may close these issues.

[bug]: guzzlehttp/psr7 constraint (^2.0) prevents clean installation on modern Laravel applications

2 participants