I have problem with my web server hosted in php:8.0-apache
docker container, always returning status code 200, even if it's set to different value. Same code outside of container works correctly
my php.ini
file is:
log_errors=On
error_log=/dev/stderr
and php code is:
... some code ...
http_response_code(400);
exit;
but I receive response:
HTTP/1.1 200 OK
Any ideas what's wrong with my setup?
edit: docker file:
FROM php:8.0-apache
RUN echo "<?php echo '{some json content}'; http_response_code(400); exit; ?>" >> /var/www/html/index.php
COPY php.ini /usr/local/etc/php/
CodePudding user response:
I figured what was the problem:
there was already sent header with status 200 when I called echo "..."
, so http_response_code(400)
was ignored.
To solve this issue (and reason why it was working with default configuration on my pc) is to set output_buffering
in php.ini
to some value, so output is not sent immediately.
log_errors=On
error_log=/dev/stderr
output_buffering=4096