Hello,

Sometimes, due to database problems, my Drupal sites go offline. The database server always says it is online when I face these problems. I am trying to solve the problems causing the database errors by one by, but in any case it will be good to be notified by mail in case of Drupal's database connectivity problems.

There are some solutions about editing maintenance mode template file to add email functions to these template. I tried this solution and I got 1000+ e-mails, therefore I got a warning from my host. I am searching a way to make these e-mail function feasible (i.e. once in 15 minutes or 30 minutes). Are there any such possibilities?

If this feature is needed to be developed, I can surely code but I am not very well in Drupal coding. Any hints and tips for this topic is also welcomed.

Note: I am using Drupal 6.

Comments

Since database connectivity

Since database connectivity is the issue you can't use a database variable, but you could use a text file-
Have your email function check for a file called 'last_db_warning.txt' or whatever and load it. If found it has a timestamp.
if the timestamp is past your threshold, send the email and save the current timestamp to the file. This should prevent you spamming yourself and getting another slap from your hosting company.
Something like:

<?php
 
// define threshold in seconds. 900=15min, 1800=30min etc
 
define('DB_WARNING_EMAIL_THRESHOLD', 900);

 
$last_warning_sent = file_get_contents('/path/to/your/file/last_db_warning.txt');
 
// file_get_contents returns FALSE if file does not exist
 
if (!$last_warning_sent ||  ((time() - $last_warning_sent) > DB_WARNING_EMAIL_THRESHOLD)) {
   
// First resave file so we don't get whacked by an email sending error
   
file_put_contents('/path/to/your/file/last_db_warning.txt', time()); // creates or overwrites file
    // .... send your email notification
 
}
?>

You may wrap that in a function call depending on how you are qualifying sending the email.

I'm unique, just like everybody else.
If I helped, please pay it forward, backward or sidelong.

Thank you!

Thank you for the tip NotGoddess.