11
11
12
12
namespace Symfony \Component \HttpClient ;
13
13
14
+ use Amp \Http \Client \Connection \ConnectionLimitingPool ;
14
15
use Symfony \Contracts \HttpClient \HttpClientInterface ;
15
16
16
17
/**
@@ -29,6 +30,25 @@ final class HttpClient
29
30
*/
30
31
public static function create (array $ defaultOptions = [], int $ maxHostConnections = 6 , int $ maxPendingPushes = 50 ): HttpClientInterface
31
32
{
33
+ if ($ amp = class_exists (ConnectionLimitingPool::class)) {
34
+ if (!\extension_loaded ('curl ' )) {
35
+ return new AmpHttpClient ($ defaultOptions , null , $ maxHostConnections , $ maxPendingPushes );
36
+ }
37
+
38
+ // Skip curl when HTTP/2 push is unsupported or buggy, see https://bugs.php.net/77535
39
+ if (\PHP_VERSION_ID < 70217 || (\PHP_VERSION_ID >= 70300 && \PHP_VERSION_ID < 70304 ) || !\defined ('CURLMOPT_PUSHFUNCTION ' )) {
40
+ return new AmpHttpClient ($ defaultOptions , null , $ maxHostConnections , $ maxPendingPushes );
41
+ }
42
+
43
+ static $ curlVersion = null ;
44
+ $ curlVersion = $ curlVersion ?? curl_version ();
45
+
46
+ // HTTP/2 push crashes before curl 7.61
47
+ if (0x073d00 > $ curlVersion ['version_number ' ] || !(CURL_VERSION_HTTP2 & $ curlVersion ['features ' ])) {
48
+ return new AmpHttpClient ($ defaultOptions , null , $ maxHostConnections , $ maxPendingPushes );
49
+ }
50
+ }
51
+
32
52
if (\extension_loaded ('curl ' )) {
33
53
if ('\\' !== \DIRECTORY_SEPARATOR || ini_get ('curl.cainfo ' ) || ini_get ('openssl.cafile ' ) || ini_get ('openssl.capath ' )) {
34
54
return new CurlHttpClient ($ defaultOptions , $ maxHostConnections , $ maxPendingPushes );
@@ -37,6 +57,10 @@ public static function create(array $defaultOptions = [], int $maxHostConnection
37
57
@trigger_error ('Configure the "curl.cainfo", "openssl.cafile" or "openssl.capath" php.ini setting to enable the CurlHttpClient ' , E_USER_WARNING );
38
58
}
39
59
60
+ if ($ amp ) {
61
+ return new AmpHttpClient ($ defaultOptions , null , $ maxHostConnections , $ maxPendingPushes );
62
+ }
63
+
40
64
return new NativeHttpClient ($ defaultOptions , $ maxHostConnections );
41
65
}
42
66
0 commit comments