msgraph-sdk-php
msgraph-sdk-php copied to clipboard
Request fails due to HTTP/2 being enabled on PHP 8.0.13
The Problem
I am using this lib for a variety of things, but the following call fails after an upgrade from 1.56.0 to 1.57.1:
$graph = new Graph();
$graph->setAccessToken($accessToken->getToken()); // yes, the token actually has a value, I've checked.
$user = $graph->createRequest('GET', '/me?$select=displayName,userPrincipalName,id')
->setReturnType(User::class)
->execute();
This error (and similar) is printed out three times, despite the auth token being valid:
{"error":{"code":"InvalidAuthenticationToken","message":"Access token is empty.","innerError":{"date":"2022-04-06T20:28:46","request-id":"e61b8687-2080-4a3d-bfe0-dec001f25f54","client-request-id":"e61b8687-2080-4a3d-bfe0-dec001f25f54"}}}
Along with the following error:
cURL error 0: The cURL request was retried 3 times and did not succeed. The most likely reason for the failure is that cURL was unable to rewind the body of the request and subsequent retries resulted in the same error. Turn on the debug option to see what went wrong. See https://bugs.php.net/bug.php?id=47204 for more information. (see https://curl.haxx.se/libcurl/c/libcurl-errors.html) for https://graph.microsoft.com/v1.0/me?$select=displayName,userPrincipalName,id
I have determined that this code is what has broken this:
https://github.com/microsoftgraph/msgraph-sdk-php/blob/2ad83c3dd7f5edab3daaf6033451b77d278576bd/src/Http/GraphRequest.php#L548-L552
If I manually comment out $clientSettings['version'] = '2';
OR downgrade to 1.56.0 (before this change was made), then everything works.
Expected
I expect my call to the graph request lib to, well, succeed. :)
Environment
I am running PHP 8.0.13 on macOS 11.6.5 through XAMPP. For the record, on production on an Ubuntu server running 8.0.16, everything is fine, so it must be something with the local PHP version/OS/setup.
Thank you!!
Encountered same issue on PHP 7.4 and 7.3 (running as FPM in a Plesk environment).
if( extension_loaded( 'curl' ) && defined( 'CURL_VERSION_HTTP2' ) && ( curl_version()["features"] & CURL_VERSION_HTTP2 !== 0 ) ) {
// Enable HTTP/2 if curl lib exists and supports it
$clientSettings['version'] = '2';
}
I had to comment that out to solve the issue (I had to rewrite my own createGuzzleClient() to add a log handler), so didn't need to touch the msgraph-sdk-php code.
What's funny is that before that I tried to disable HTTP/2 on my server (yes like using a hammer versus a fly) without success.
@Deadpikle @ZalemCitizen You saved my day! Was debugging this for hours... 👍
I'm getting the same error, however, the request works as expected with http/2 enabled (php 7.4.30) in a test environment but not in prod (where we are not yet using http/2)
@Ndiritu do you think this will be fixed soon? Thanks.
Update on this issue. "Starting in version 7.43.0, libcurl fully supports HTTP/2 multiplexing". An update to our server OS to ensure a newer version of curl fixed this error.
Anything new on this issue?
@Deadpikle @ZalemCitizen @Adstokoe19 @dhaggman are you able to share the curl version you're running? PHP sample
curl_version()["version"];
curl_version()["features"];
Might be a bug in my checks for whether is HTTP/2 enabled on the underlying libcurl version
Version 1.87.0
contains a bug fix on the checks before enabling HTTP/2 on Guzzle.
Please let me know if this resolves the issue
No further correspondence from customers. Please re-open if this is not fixed