Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Send HTTP 500 status code on fatal errors with Symfony.
<?php
/**
* This could be the Bundle class of your main bundle.
*/
namespace Acme\DemoBundle;
use Symfony\Component\HttpKernel\Bundle\Bundle;
class AcmeDemoBundle extends Bundle
{
public function boot()
{
register_shutdown_function(array($this, 'handleFatalError'));
}
public function handleFatalError()
{
if (null === $error = error_get_last()) {
return;
}
$type = $error['type'];
if (!in_array($type, array(E_ERROR, E_CORE_ERROR, E_COMPILE_ERROR, E_PARSE))) {
return;
}
header('HTTP/1.1 500 Internal Server Error');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment