Error Handling on 1&1
Posted: Mon Sep 12, 2011 3:45 pm
I recently found out that my hosting provider, 1&1, does not provide Apache error logs for sites that are hosted on shared servers. They recommend that the site implement its own error logging scheme and provided the following code snippet that can be inserted/included into a PHP script:
Question for the knowledgable on this forum is, will the above code snippet work if I paste/include it into index.php? (assuming latest version of CMSMS and PHP 5.x)
The original 1&1 FAQ page is here: http://faq.1and1.com/miscellaneous/14.html
TIA,
Sanjay
Code: Select all
error_reporting(0);
$old_error_handler = set_error_handler("userErrorHandler");
function userErrorHandler ($errno, $errmsg, $filename, $linenum, $vars)
{
$time=date("d M Y H:i:s");
// Get the error type from the error number
$errortype = array (1 => "Error",
2 => "Warning",
4 => "Parsing Error",
8 => "Notice",
16 => "Core Error",
32 => "Core Warning",
64 => "Compile Error",
128 => "Compile Warning",
256 => "User Error",
512 => "User Warning",
1024 => "User Notice");
$errlevel=$errortype[$errno];
//Write error to log file (CSV format)
$errfile=fopen("errors.csv","a");
fputs($errfile,"\"$time\",\"$filename:
$linenum\",\"($errlevel) $errmsg\"\r\n");
fclose($errfile);
if($errno!=2 && $errno!=8) {
//Terminate script if fatal error
die("A fatal error has occurred. Script execution has been aborted");
}
}
The original 1&1 FAQ page is here: http://faq.1and1.com/miscellaneous/14.html
TIA,
Sanjay