seohug
Regular Member
Let's say you run Wordpress, Durpal or any CMS or site that runs on PHP - which are millions out there. Your CMS or script fails to reach the database, or process a query or have some sort of an issue.
In most hosts default config, this will log an error_log with details of the issue.
You don't know that this has happened because you don't systematically login to check.
All site monitoring services will not pick this up, because your site could be up (returning http status code 200), but not function or returning some error.
How do you watch out for this?
This is where the simple free error_log Reporter script below comes in.
Just edit:
$to_email : where do you want the email to do
$from_email : let's say your site is makemoney.com, make this [email protected]
If you want, you can change Europe/London to America/Chicago or where ever you are.
Once done, copy create a file call it error_log_report.php and save it to a location where you want to monitor for error_log, usually root of your site. You can make multiple copies in other folders if needed.
Now run this on a schedule using CRON and set it to execute every minute, it runs in split second, so no performance issues. If you use cPanel, this is a piece of cake:
Just edit the path under command to be where you placed the error_log_reporter.php
Want to test it?
Create a file with the name exactly error_log and wait 1-2 minutes. If you the file doesn't get renamed and you don't get an email, go back and check for typos...etc.
I hope this helps.
In most hosts default config, this will log an error_log with details of the issue.
You don't know that this has happened because you don't systematically login to check.
All site monitoring services will not pick this up, because your site could be up (returning http status code 200), but not function or returning some error.
How do you watch out for this?
This is where the simple free error_log Reporter script below comes in.
Code:
<?php
// Author: seohug @ BHW
// The purpose of this script is to check for presence of error_log, if found, it collects it content and send it by email. It will also rename it with timestamp to prevent further alerts on the same error_log.
// edit this
$to_email = "[email protected]";
$from_email = "From: [email protected]" . "\r\n";
date_default_timezone_set("Europe/London");
$timestamp = date("d-m-Y-his");
$file = "error_log";
if (file_exists($file)) {
$file_content = file_get_contents($file);
$file_content = wordwrap($file_content,70);
echo "error_log file found with the following content\n" . $file_content;
//mail($to_email, "error_log found", $file_content, $from_email);
rename($file, $file . "-" . $timestamp . ".txt");
} else {
echo "No error file found";
}
?>
Just edit:
$to_email : where do you want the email to do
$from_email : let's say your site is makemoney.com, make this [email protected]
If you want, you can change Europe/London to America/Chicago or where ever you are.
Once done, copy create a file call it error_log_report.php and save it to a location where you want to monitor for error_log, usually root of your site. You can make multiple copies in other folders if needed.
Now run this on a schedule using CRON and set it to execute every minute, it runs in split second, so no performance issues. If you use cPanel, this is a piece of cake:

Just edit the path under command to be where you placed the error_log_reporter.php
Want to test it?
Create a file with the name exactly error_log and wait 1-2 minutes. If you the file doesn't get renamed and you don't get an email, go back and check for typos...etc.
I hope this helps.