|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #75009 http_response_code() error code support depends on SAPI
Submitted: 2017-07-31 07:17 UTC Modified: 2017-07-31 15:37 UTC
From: czirkos dot zoltan at gmail dot com Assigned:
Status: Verified Package: Apache2 related
PHP Version: 7.0.21 OS: Linux 4.4.0-62-generic #83-Ubunt
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
Solve the problem:
7 + 6 = ?
Subscribe to this entry?

 [2017-07-31 07:17 UTC] czirkos dot zoltan at gmail dot com
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:
echo "hello";

Expected result:
Proper error code sent via the server.

Please not that documenting the list of error codes (in the documentation at is not really a solution, as custom error codes can be defined.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2017-07-31 14:42 UTC]
-Status: Open +Status: Not a bug
 [2017-07-31 14:42 UTC]
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.
 [2017-07-31 15:00 UTC] 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 (, but this is more important than that.
 [2017-07-31 15:37 UTC]
-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
 [2017-07-31 15:37 UTC]
#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
that support depends on the SAPI and how to use header() as a workaround for non-standard codes would be a good idea.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Jun 15 02:01:27 2024 UTC