php - How to return an HTTP 500 code on any error, no matter what - Stack Overflow

PHOTO EMBED

Wed Nov 04 2020 08:27:07 GMT+0000 (Coordinated Universal Time)

Saved by @Bujhm #php

error_reporting(E_ALL);
ini_set('display_errors', 'on');

function fatal_error_handler($buffer) {
    header('HTTP/1.1 500 Internal Server Error');
    exit(0);
}

function handle_error ($errno, $errstr, $errfile, $errline){
    header('HTTP/1.1 500 Internal Server Error');
    exit(0);
}

ob_start("fatal_error_handler");
set_error_handler("handle_error");

//would normally cause a fatal error, but instead our output handler will be called allowing us to handle the error.
somefunction();
ob_end_flush();
content_copyCOPY

https://stackoverflow.com/questions/3052715/how-to-return-an-http-500-code-on-any-error-no-matter-what