For the first time in my long career, I am struggling to retrieve the input body of a RESTful Event Notification when the request is using Transfer-Encoding: chunked
(with Content-Type: application/json
)
$_POST
is obviously empty due to Content-Type: application/json
file_get_contents('php://input')
is always empty, hoping someone can explain why; is Apache not passing this through to php-fpm?
Attempting to retrieve the chunks using fopen
also fails?
$hSource = fopen('php://input', 'r');
$body = '';
while (!feof($hSource)) {
$chunk = fread($hSource, 1024);
$body .= $chunk;
}
fclose($hSource);
Is this a dead-end or am I going about this entirely wrong? I'm aware that if I have the service add the Content-Length header then all of the above would actually be working fine but they stress this 5-minute task would take them months to get across the line.
Apache downgrade-1.0
(ew...) also doesn't force them to send their requests as HTTP/1.0.
Thanks
In my scenario, this is due to the bug pointed out by @Phil in the comments
This specifically affects php-fpm, and for most users they can upgrade Apache to 2.4.46+.
Bug: https://bz.apache.org/bugzilla/show_bug.cgi?id=57087
If you're a Debian user, as of writing this; there isn't an official stable release for 2.4.46 yet, and it is in testing phase as shown here. We fell-back back to mod_php instead while we wait for a stable release, others may be inclined to use Nginx instead.
EDIT Debian has now released a stable version where this is fixed, it only took them 10 years, and the timing couldn't have been better.