Skip to content
This repository was archived by the owner on May 30, 2025. It is now read-only.

[HttpClient] Add a CurlClient #16

Merged
merged 15 commits into from
May 25, 2025
Merged

[HttpClient] Add a CurlClient #16

merged 15 commits into from
May 25, 2025

Conversation

adamziel
Copy link
Contributor

@adamziel adamziel commented May 23, 2025

Adds a CurlClient class to benefit from libcurl when available:

$client = Client::create();
// $client is CurlClient when libcurl extension is available and SocketClient otherwise

$client->fetch("https://w.org");

Motivateion

Curl is faster than stream_socket_* functions and supports more HTTP features (e.g. HTTP 2.0).

Implementation

Before this PR there was a single Client class that used stream_socket_* functions for managing HTTP connections.

After this PR there's:

  • Client abstract class with Client::create( $options ) method.
  • SocketClient – the previous Client class.
  • CurlClient – the new libcurl-based HTTP client.

The event-based API remains the same. Both clients pass a similar test suite.

Testing instructions

Confirm the tests worked

@adamziel adamziel requested a review from Copilot May 23, 2025 21:08
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR refactors the HTTP client by introducing a new CurlClient that leverages libcurl for improved performance and feature support, while keeping backward compatibility with the existing SocketClient. Key changes include:

  • Adding the CurlClient class with a new event loop and cURL callbacks.
  • Updating tests and client references to support both CurlClient and SocketClient.
  • Refactoring several client usages and documentation to reflect the new design.

Reviewed Changes

Copilot reviewed 29 out of 29 changed files in this pull request and generated 3 comments.

File Description
components/HttpClient/Tests/* Updated tests to reference the new client classes and expected cURL error messages.
components/HttpClient/Response.php Updated constructor signature and added header parsing improvements to support HTTP/2.0 responses.
components/HttpClient/Client/CurlClient.php Introduced the CurlClient implementation with cURL multi-handle management and callbacks.
components/Blueprints/* Updated type hints from Client to SocketClient to align with the client changes.

@adamziel adamziel merged commit 87a1f4a into trunk May 25, 2025
21 checks passed
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant