guzzle / promises

Promises/A+ library for PHP with synchronous support
MIT License
7.61k stars 116 forks source link

StreamHandler and HTTP/2 does not seem to work #138

Closed compelling closed 3 years ago

compelling commented 3 years ago

PHP version: 7.4.16

Description Have a php backend that uses Apple push notification (APN). As of April 1 2021, Apple only support HTTP/2 and thus I tried out this param with curl. Turns out my hosting provider only has an old lib curl, so wanted to give Guzzle a try as it states it is independent af curl. However, I cant get Guzzle to work as expected. The code below runs as it should when I just use $client = new Client() and thus depend on curl if running on a server with a new curl installed (and thus HTTP/2 support). If i create the client using StreamHandler i just get an exception when invoking client->post (An error was encountered while creating the response). Not sure why this does not work, perhaps a bug?

How to reproduce // $client = new Client();
$handler = new StreamHandler; // set streamhandler to make guzzle avoid using old curl on unoeuro $client = new Client(['handler' => $handler]); $pem_secret = "mysecret"; $pem_file = DIR.'/certificate.pem'; $base_url = "https://api.push.apple.com:443/3/device/"; $apns_topic = 'com.company.myapp'; // apple bundle id $expiry = time() + 60; $priority = 5; $headers = ["apns-topic" => $apns_topic, "apns-expiration" => $expiry, "apns-priority" => $priority]; foreach ($receivers as $token) { $url = $base_url.$token; $res = $client->post($url, [ 'headers' => $headers, 'json' => $body, 'debug' => true, 'version' => 2.0, 'cert' => [$pem_file, $pem_secret] ]);

GrahamCampbell commented 3 years ago

Yes, that's correct. Guzzle does not support HTTP 2.

GrahamCampbell commented 3 years ago

See https://github.com/guzzle/guzzle/issues/1249. We'd certainly review a PR to add HTTP 2 support if you'd like to implement it.