If your server started to interpret php file and after this 500 error occurred this means some fatal error happened in your code. It might be anything, from simple typo to execution time limit reached.
The best and only way to catch fatal errors in PHP is with register_shutdown_function. You should define it on top of your working file:
function handle_fatal() {
$error = error_get_last(); // PHP 5.2+
if($error !== NULL){
$error_landing_page = '[FATAL] '.$error['message'].' in '.$error['file'].':'.$error['line'] . '<br/>GET:<br/>' . print_r($_GET, true) . '<br/>POST:<br/>' . print_r($_POST, true);
// mail here if you need that and include $_GET, $_POST variables - this will be the last state before error occurred
exit($error_landing_page);
}
}
register_shutdown_function('handle_fatal');
Simple test case:
// put handling function at the very beginning
function handle_fatal() {/*...*/}
register_shutdown_function('handle_fatal');
// now do some logic
if($_GET['page'] == 'dupa'){
$_POST['subpage'] = 1; // more and more logic
$obj = new Dupa(); // class not found exception
}
This is what I get with my handle_fatal from example:
[FATAL] Class 'Dupa' not found in /var/www/index.php:22
GET:
Array ( [page] => dupa )
POST:
Array ( [subpage] => 1 )
After all you should know that catching such errors is not always best idea and you should be careful about it.