Dec
4
WordPress Plugin: MySQL Server Crash Monitor
Filed Under development |
Since end of October our MySQL Server crashed on or two times a day. We don’t no exactly why. Maybe the Databases are to big. We run several WordPress system on this MySQL Server. but the MySQL services often crashed, then my WordPress can’t connect to MySQL server and show the error. So I develop this program to monitor the WordPress MySQL server, when the server is down, WordPress will auto send me an e-mail and write to a text log file in a recorded. We can look trough the log file to analysis the MySQL server databse, in order to cantact the host administrators to fix the error.
Here is the source code of the MySQL Server Crash Monitor.
// Change the e-mail address below .
$from = "webmaster@moon-blog.com";
$to = "webmaster@moon-blog.com";
$subject = "MySQL Crashed!";
$body = date("Y-m-d H:i:s");
$headers = 'From: '.$from . "\r\n"
.'Reply-To: '.$from . "\r\n"
.'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $body, $headers);
// Log to file
$filename = 'log.txt';
$somecontent = date("Y-m-d H:i:s");
$somecontent = $somecontent . "\r\n";
if (is_writable($filename)) {
if (!$handle = fopen($filename, 'a')) {
exit;
}
if (!fwrite($handle, $somecontent)) {
exit;
}
fclose($handle);
}
First, upload a file named log.txt to the WordPress root directory, chmod it to 666.
Second, replace the e-mail address of the code to your own e-mail.
Then,opening wp-includes/wp-db.php, find “if (! $ This-> dbh)”, 66 lines in WordPress 2.3.1, paste the code after that. Save and upload the file.
Now, When the database lost connection or get problems, WordPress will automatically mail the error message to your mailbox, at the same time the message will be recorded in log.txt document.
Hello,
We are trying to debug a server that will run wordpress 2.3.3 but chokes on 2.5.1 will this work with wordpress 2.5.1?
Best regards,
Matthew
Check out these 26 traffic machines that will take a your product to a new level by pulling traffic from a lot of different places.
word press is really kind of fantastic.
[...] Edition of this plug-in unit English: WordPress Plugin: MySQL Server Crash Monitor [...]
[...] 越来越多的网友开始使用国外的虚拟主机来建立自己的博客,但有些主机的数据库服务器并不是十分稳定。月光博客开发的监视MySQL数据库服务器的插件,可以在你的数据库服务器出现问题的时候,自动给你发送Email提醒,以便及时处理。这里是月光博客关于此插件的详细介绍。下载地址。 [...]
[...] 本插件英文版:WordPress Plugin: MySQL Server Crash Monitor [...]