Skip to content

[HttpClient] Document AMPHP HttpClient integration for HTTP/2 #13487

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

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 19 additions & 6 deletions components/http_client.rst
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,13 @@ with HTTP/2 and with doing concurrent asynchronous streamed and multiplexed
requests/responses. Even when doing regular synchronous calls, this design
allows keeping connections to remote hosts open between requests, improving
performance by saving repetitive DNS resolution, SSL negotiation, etc.
To leverage all these design benefits, the cURL extension is needed.

Enabling cURL Support
~~~~~~~~~~~~~~~~~~~~~

This component supports both the native PHP streams and cURL to make the HTTP
requests. Although both are interchangeable and provide the same features,
including concurrent requests, HTTP/2 is only supported when using cURL.
requests. Both are interchangeable and provide the same features, including
concurrent requests and HTTP/2 support.

``HttpClient::create()`` selects the cURL transport if the `cURL PHP extension`_
is enabled and falls back to PHP streams otherwise. If you prefer to select
Expand All @@ -75,9 +74,21 @@ is installed and enabled. Otherwise, the native PHP streams will be used.
HTTP/2 Support
~~~~~~~~~~~~~~

When requesting an ``https`` URL, HTTP/2 is enabled by default if libcurl >= 7.36
is used. To force HTTP/2 for ``http`` URLs, you need to enable it explicitly via
the ``http_version`` option::
.. versionadded:: 5.1

Integration with ``amphp/http-client`` was introduced in Symfony 5.1.
Prior to this version, HTTP/2 was only supported when ``libcurl`` was
installed.

The component supports HTTP/2 if one of the following tools is
installed:

* The `libcurl`_ package version 7.36 or higher;
* The `amphp/http-client`_ Packagist package version 4.2 or higher.

When requesting an ``https`` URL and HTTP/2 is supported by your server,
HTTP/2 is enabled by default. To force HTTP/2 for ``http`` URLs, you need
to enable it explicitly via the ``http_version`` option::

$client = HttpClient::create(['http_version' => '2.0']);

Expand Down Expand Up @@ -1021,3 +1032,5 @@ However, using ``MockResponse`` allows simulating chunked responses and timeouts
.. _`PSR-18`: https://www.php-fig.org/psr/psr-18/
.. _`HTTPlug`: https://github.com/php-http/httplug/#readme
.. _`Symfony Contracts`: https://github.com/symfony/contracts
.. _`libcurl`: https://curl.haxx.se/libcurl/
.. _`amphp/http-client`: https://packagist.org/packages/amphp/http-client