Skip to content
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

Enable HTTP/2 for CURL #727

Closed
atbreuer11 opened this issue Aug 27, 2020 · 7 comments · Fixed by #740
Closed

Enable HTTP/2 for CURL #727

atbreuer11 opened this issue Aug 27, 2020 · 7 comments · Fixed by #740

Comments

@atbreuer11
Copy link

I have a lumen based API using the php-74-fpm layer as well as a custom layer to add sqlsrv extensions. When using the curl extension to make a request to Apple's APNs, I am receiving the following error:

production.INFO: APNS request response: �������@��@u��Unexpected HTTP/1.x request

The cause seems simple enough, Bref's provided environment does not have HTTP/2 enabled for the curl extension. According to this Stackoverflow answer, there is a compile time option to enable HTTP/2.

This link may also be helpful: curl http2 docs

If anyone has been able to enable this functionality via a custom layer, I would appreciate any guidance.

@mnapoli
Copy link
Member

mnapoli commented Aug 28, 2020

Sounds good, if anyone wants to work on a PR that's perfect!

Thanks for the details!

@shouze
Copy link
Contributor

shouze commented Sep 2, 2020

@atbreuer11 looks weird regarding this docker-library/php#567 (comment) and that

ENV VERSION_CURL=7.63.0

so... haven't tested yet but maybe related on the fact that your curl request is made by using HTTP/1 mode? 🤔
Could you please provide some code sample to reproduce your http client call?

@atbreuer11
Copy link
Author

@shouze Here is the relevant code. I believe this is identical to the code I had been using locally, which was making successful HTTP/2 requests (to the Apple APNs servers).

if (!defined('CURL_HTTP_VERSION_2_0')) {`
   define('CURL_HTTP_VERSION_2_0', 3);
}

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_2);

$response = curl_exec($ch);

curl_close($ch);

@shouze
Copy link
Contributor

shouze commented Sep 5, 2020

Thanks! And can you please provide php layer version that you use?

@atbreuer11
Copy link
Author

@shouze I'm using the php-74 layer (the non-fpm version).

@shouze
Copy link
Contributor

shouze commented Sep 8, 2020

@atbreuer11 thx, and which region & version of the layer runtime (latest ones are listed here for example)?

@shouze
Copy link
Contributor

shouze commented Sep 8, 2020

Ok anyway I've checked on various php docker images and yes we miss HTTP2 support on bref's php:

❯ docker run php:7.4 php -i | grep HTTP2
HTTP2 => Yes

~ took 675ms 
❯ docker run php:7.4-alpine php -i | grep HTTP2
HTTP2 => Yes

~ took 751ms 
❯ docker run --entrypoint= bref/php-74:latest php -i | grep HTTP2
HTTP2 => No

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants