Skip to content

Commit d883b01

Browse files
[HttpClient] make HttpClient::create() return an AmpHttpClient when amphp/http-client is found but curl is not or too old
1 parent 24b9fa4 commit d883b01

File tree

1 file changed

+28
-10
lines changed

1 file changed

+28
-10
lines changed

http_client.rst

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -854,15 +854,28 @@ To leverage all these design benefits, the cURL extension is needed.
854854
Enabling cURL Support
855855
~~~~~~~~~~~~~~~~~~~~~
856856

857-
This component supports both the native PHP streams and cURL to make the HTTP
858-
requests. Although both are interchangeable and provide the same features,
859-
including concurrent requests, HTTP/2 is only supported when using cURL.
857+
This component supports the native PHP streams, ``amphp/http-client`` and cURL to
858+
make the HTTP requests. Although they are interchangeable and provide the
859+
same features, including concurrent requests, HTTP/2 is only supported when
860+
using cURL or ``amphp/http-client``.
861+
862+
.. note::
863+
864+
To use the :class:`Symfony\\Component\\HttpClient\\AmpHttpClient`, the
865+
`amphp/http-client`_ package must be installed.
866+
867+
.. versionadded:: 5.1
868+
869+
Integration with ``amphp/http-client`` was introduced in Symfony 5.1.
860870

861871
The :method:`Symfony\\Component\\HttpClient\\HttpClient::create` method
862-
selects the cURL transport if the `cURL PHP extension`_ is enabled and falls
863-
back to PHP streams otherwise. If you prefer to select the transport
864-
explicitly, use the following classes to create the client::
872+
selects the cURL transport if the `cURL PHP extension`_ is enabled. It falls
873+
back to ``AmpHttpClient`` if cURL couldn't be found or is too old. Finally, if
874+
``AmpHttpClient`` is not available, it falls back to PHP streams.
875+
If you prefer to select the transport explicitly, use the following classes
876+
to create the client::
865877

878+
use Symfony\Component\HttpClient\AmpHttpClient;
866879
use Symfony\Component\HttpClient\CurlHttpClient;
867880
use Symfony\Component\HttpClient\NativeHttpClient;
868881

@@ -872,9 +885,12 @@ explicitly, use the following classes to create the client::
872885
// uses the cURL PHP extension
873886
$client = new CurlHttpClient();
874887

888+
// uses the client from the `amphp/http-client` package
889+
$client = new AmpHttpClient();
890+
875891
When using this component in a full-stack Symfony application, this behavior is
876892
not configurable and cURL will be used automatically if the cURL PHP extension
877-
is installed and enabled. Otherwise, the native PHP streams will be used.
893+
is installed and enabled, and will fall back as explained above.
878894

879895
Configuring CurlHttpClient Options
880896
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -984,9 +1000,10 @@ To force HTTP/2 for ``http`` URLs, you need to enable it explicitly via the
9841000
9851001
$client = HttpClient::create(['http_version' => '2.0']);
9861002
987-
Support for HTTP/2 PUSH works out of the box when libcurl >= 7.61 is used with
988-
PHP >= 7.2.17 / 7.3.4: pushed responses are put into a temporary cache and are
989-
used when a subsequent request is triggered for the corresponding URLs.
1003+
Support for HTTP/2 PUSH works out of the box when using ``amphp/http-client``
1004+
or when libcurl >= 7.61 is used with PHP >= 7.2.17 / 7.3.4: pushed responses
1005+
are put into a temporary cache and are used when a subsequent request is
1006+
triggered for the corresponding URLs.
9901007

9911008
Processing Responses
9921009
--------------------
@@ -2055,3 +2072,4 @@ test it in a real application::
20552072
.. _`EventSource`: https://www.w3.org/TR/eventsource/#eventsource
20562073
.. _`idempotent method`: https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol#Idempotent_methods
20572074
.. _`SSRF`: https://portswigger.net/web-security/ssrf
2075+
.. _`AmpHttpClient`: https://github.com/amphp/http-client

0 commit comments

Comments
 (0)