Skip to content

Instantly share code, notes, and snippets.

@uuf6429
Last active May 17, 2026 22:52
Show Gist options
  • Select an option

  • Save uuf6429/6719756 to your computer and use it in GitHub Desktop.

Select an option

Save uuf6429/6719756 to your computer and use it in GitHub Desktop.
PHP Post-Mortem Tool
<?php
register_shutdown_function(static function () {
while (ob_get_level() > 0) {
ob_end_clean();
}
ob_implicit_flush(true);
echo "<!--\n";
echo "\n\tHeaders Sent:";
$file = $line = null;
headers_sent($file, $line);
$file = empty($file) ? 'unknown' : $file;
echo "\n\t\tat $file:$line";
echo "\n\tLast Error:";
$lastError = error_get_last();
if (!empty($lastError)) {
foreach (get_defined_constants(true)['Core'] as $name => $constantValue) {
if (substr($name, 0, 2) === 'E_' && $constantValue === $lastError['type']) {
$lastError['type'] = $name;
break;
}
}
echo str_replace("\n", "\n\t\t", htmlspecialchars("\n{$lastError['message']} ({$lastError['type']}) in {$lastError['file']}:{$lastError['line']}"));
} else {
echo "\n\t\tnone";
}
echo "\n\tIncluded Files:";
echo "\n\t\t" . implode("\n\t\t", get_included_files());
echo "\n-->";
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment