stackery / php-lambda-layer

PHP Runtime Layer for AWS Lambda
Other
320 stars 70 forks source link

php warnings/errors attached to output #22

Closed gszeszko closed 5 years ago

gszeszko commented 5 years ago

Whenever there are php warnings/notice/errors generated by the executing script/handler they are prepanded to the output generated by the script. These messages are formatted as html which really messes up the output (which at least in my case is json). Because that output is streamed first, the calls to the header() function generate their own warnings since that call may not follow actual output data. Furthermore, it appears that the returned html code in that case is always 200 ok, regardless of what the script actually returned.

txase commented 5 years ago

I may be wrong, but I think this is expected behavior by PHP. Here's a Stack Overflow post addressing how to render errors when the expected content-type is JSON: https://stackoverflow.com/questions/41432689/report-php-errors-in-json-format-complying-with-the-regular-content-type.

I'm going to close this issue as I believe the layer is behaving correctly. Please reopen if you feel otherwise.

Thanks!

gszeszko commented 5 years ago

@txase I noticed that calling error_log will route messages to the cloudwatch of the lambda instance. That would work just for me for reporting errors. Are you saying that if I add my own error handler and from there route to error_log and thus cloudwatch, then your layer will honor that?

Can I put these lines into my php.ini file in order to fine tune error reporting?

php_flag display_errors 1 php_flag display_startup_errors 1 php_value error_reporting 32767

txase commented 5 years ago

Yes, if you set a custom error handler that responds with json after an error occurs then everything should work correctly.

gszeszko commented 5 years ago

I was able to get error handling to work by setting up a shutdown handler to deal with errors and other abnormal termination.

txase commented 5 years ago

Great!