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

PHP Zlib Extension not woking #814

Closed
poovarasudev opened this issue Dec 7, 2020 · 5 comments
Closed

PHP Zlib Extension not woking #814

poovarasudev opened this issue Dec 7, 2020 · 5 comments
Labels

Comments

@poovarasudev
Copy link

poovarasudev commented Dec 7, 2020

Hi,

I have deployed a simple php application which has default compression enabled.

I'm using "ini_set('zlib.output_compression', 'On');" to compress the responses. But I'm receiving "Internal Server Error" as the response.

I tried to manually compress the response by using gzencode() - zlib's function to get the compressed output. Still I'm facing the same issue.
![Screensho
Screenshot 2020-12-07 at 12 45 32 PM

@mnapoli
Copy link
Member

mnapoli commented Dec 7, 2020

What is the error message in the logs?

@poovarasudev
Copy link
Author

@mnapoli While using gzencode(), I'm getting this :

2946e38f-7a46-43ea-8993-e4cb6f9ea4ee Invoke Error
{
"errorType": "Exception",
"errorMessage": "The Lambda response cannot be encoded to JSON.\nThis error usually happens when you try to return binary content. If you are writing an HTTP application and you want to return a binary HTTP response (like an image, a PDF, etc.), please read this guide: https://bref.sh/docs/runtimes/http.html#binary-responses\nHere is the original JSON error: 'Malformed UTF-8 characters, possibly incorrectly encoded'",
"stack": [
"#0 /var/task/vendor/bref/bref/src/Runtime/LambdaRuntime.php(187): Bref\Runtime\LambdaRuntime->postJson()",
"#1 /var/task/vendor/bref/bref/src/Runtime/LambdaRuntime.php(104): Bref\Runtime\LambdaRuntime->sendResponse()",
"#2 /opt/bootstrap(35): Bref\Runtime\LambdaRuntime->processNextEvent()",
"#3 {main}"
]
}

@mnapoli
Copy link
Member

mnapoli commented Dec 7, 2020

I guess you have your answer right here then.

@mnapoli mnapoli closed this as completed Dec 7, 2020
@mnapoli mnapoli added support and removed bug labels Dec 7, 2020
@poovarasudev
Copy link
Author

@mnapoli After handling binary-response, I'm getting the response status code as '200'. But the response is not decoded properly. Facing ERR_CONTENT_DECODING_FAILED issue in the browser.
Screenshot 2020-12-07 at 7 02 50 PM

FYI : Also there is no error logs in CloudWatch.

  • This same code working fine in a Linux machine

@mnapoli
Copy link
Member

mnapoli commented Dec 7, 2020

I think PHP's zlib.output_compression is not compatible with Lambda and API Gateway.

Have a look at https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-gzip-compression-decompression.html and https://www.serverless.com/plugins/serverless-api-compression if you really want to implement that.

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

No branches or pull requests

2 participants