Bug->Doc #75009 [Nab->Ver]: http_response_code() error code support depends on SAPI
| From: | requinix@php.net | Date: | Mon, 31 Jul 2017 15:37:53 +0000 |
| Subject: | Bug->Doc #75009 [Nab->Ver]: http_response_code() error code support depends on SAPI | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-14876@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=75009&edit=1
ID: 75009
Updated by: requinix@php.net
Reported by: czirkos dot zoltan at gmail dot com
-Summary: http_response_code() fails on nonstandard error code
+Summary: http_response_code() error code support depends on
SAPI
-Status: Not a bug
+Status: Verified
-Type: Bug
+Type: Documentation Problem
Package: Apache2 related
Operating System: Linux 4.4.0-62-generic #83-Ubunt
PHP Version: 7.0.21
Block user comment: N
Private report: N
New Comment:
#116880 is partially correct in that PHP does use that list, but it's only for php-fpm, the
built-in dev server, and when running as regular CGI (as far as I can see).
A note along the lines of
http://php.net/manual/en/function.http-response-code.php#114996
that support depends on the SAPI and how to use header() as a workaround for non-standard codes
would be a good idea.
Previous Comments:
------------------------------------------------------------------------
[2017-07-31 15:00:44] czirkos dot zoltan at gmail dot com
Thank you for the clarification. It might be a good idea to mention this in the documentation;
something like "Available response codes depend on the server software used". There's
a comment about that (http://php.net/manual/en/function.http-response-code.php#116880), but this is
more important than that.
------------------------------------------------------------------------
[2017-07-31 14:42:50] requinix@php.net
http_response_code() depends on the SAPI (Apache or FPM+nginx) supporting the code. nginx
doesn't mind a custom 210 but Apache does and it (not PHP) substitutes a 500 instead [1].
If you want a custom status then use header(), which Apache handles differently than if you just
give the code.
header("HTTP/1.1 210 Whatever That Code Means");
[1] They support 200 OK through 208 Already Reported. Anything 2xx above that will be rejected. See
their modules/http/http_protocol.c for more.
https://svn.apache.org/viewvc/httpd/httpd/branches/2.4.x/modules/http/http_protocol.c?revision=1799890
------------------------------------------------------------------------
[2017-07-31 07:17:06] czirkos dot zoltan at gmail dot com
Description:
------------
The http_response_code() function fails for a nonstandard error code (eg. 210). 500 Internal Server
Error is emitted instead.
This only happens with the apache2handler SAPI; eg. Nginx+FPM works fine.
Test script:
---------------
http_response_code(210);
echo "hello";
Expected result:
----------------
Proper error code sent via the server.
Please not that documenting the list of error codes (in the documentation at http://php.net/manual/en/function.http-response-code.php)
is not really a solution, as custom error codes can be defined.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=75009&edit=1