Php-graph-sdk: Undefined offset: 1 (enabled HTTP/2 support in the Curl library used by PHP)

Created on 5 Nov 2018  路  6Comments  路  Source: facebookarchive/php-graph-sdk

https://github.com/facebook/php-graph-sdk/blob/3138249d85e8dc040f15bedd3581a3c616f49005/src/Facebook/Http/GraphRawResponse.php#L107

From today I am getting error like in title. I can see in logs this call:

Facebook\Http\GraphRawResponse->setHttpResponseCodeFromHeader('HTTP/2 200 ')

It doesn't match to regex in code:
|HTTP/\d\.\d\s+(\d+)\s+.*|

The problem appeared after we enabled HTTP/2 support in the Curl library used by PHP.

It should be solve problem i guess:
/HTTP\/\d(?:\.\d)?\s+(\d+)\s+/

Someone else getting the same error?

We are using SDK v. 5.6.3.

Most helpful comment

The solution in @bytestream's pull request avoids using a complicated regular expression entirely:

// https://tools.ietf.org/html/rfc7230#section-3.1.2
list($version, $status, $reason) = array_pad(explode(' ', $rawResponseHeader, 3), 3, null);
$this->httpResponseCode = (int) $status;

It also may be good to throw an exception if $status is not a valid number.

All 6 comments

I also recommend using the standard delimiter (/) instead of the one used in your code (|).
It only complicates the code and makes it less universal.

Just ran into this after libcurl was automatically updated:
ea-libcurl.x86_64 0:7.61.1-1.1.1.cpanel
to
ea-libcurl-7.62.0-1.1.1.cpanel.x86_64

Will submit a PR.

Dangerous programming- they are assuming that they will always get a match back from preg_match.

Atleast it should be HTTP\/\d(?:\.\d)?\s+(\d+)

/HTTP\/\d(?:.\d)?s+(\d+)s+/

This won't work in this case.

HTTP/1.1 400

The solution in @bytestream's pull request avoids using a complicated regular expression entirely:

// https://tools.ietf.org/html/rfc7230#section-3.1.2
list($version, $status, $reason) = array_pad(explode(' ', $rawResponseHeader, 3), 3, null);
$this->httpResponseCode = (int) $status;

It also may be good to throw an exception if $status is not a valid number.

Why fix me that do not work, Please give me. Thank you.
Error message:
Ooophs, we got an error: Facebook Graph returned an error: The request is invalid because the app is configured as a desktop app

Was this page helpful?
0 / 5 - 0 ratings