Default all responses to 500 before any code is run so PHP will throw 500's on FATAL errors

Created on 17 March 2016, about 9 years ago
Updated 28 May 2025, 11 days ago

Problem/Motivation

If PHP throws a FATAL error, a 200 response will be returned.

This could mean that the 200 'OK' response gets cached by a browser, a reverse proxy, or a CDN.

Proposed resolution

I was sure PHP could return a 500 is maybe display_errors were turned off, but from testing this wasn't happening for me.

If we set the status code to 500 in index.php, before any other code is run, we can ensure that PHP will return a 500 response code for FATAL errors. All other cases will be handled by a Response object, so will have the correct/intended status code

Remaining tasks

User interface changes

API changes

Data model changes

🐛 Bug report
Status

Needs work

Version

11.0 🔥

Component

base system

Created by

🇬🇧United Kingdom damiankloip

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

  • Triaged core major

    There is consensus among core maintainers that this is a major issue. Only core committers should add this tag.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024