Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm in the process of customizing dp-error.php. I'm using the mail() function to alert me when there's a database connection problem on my website. The trouble is, what if 1000 people visit my website when it's down? Wouldn't I get 1000 emails? Here's the code I'm using to send email:

mail("email@email.com", "Database Error", "There is a problem with teh database!", "From: Your WP Installation"); ?> 

My other question is then how would mail() know it's okay to send me a notification email in a future db error? After a certain period of time send again, if there's (still) an error?

Thanks!

share|improve this question
    
Close-voted as off-topic. This is a question about a PHO function, that is not WordPress-specific. –  Chip Bennett Mar 5 '13 at 23:25
add comment

1 Answer

up vote 2 down vote accepted

I'm not sure that this is a good idea, email is just not a good medium for emergency messages (who will see the email when you are a sleep or at the beach?), and if you want to monitor the site it is better done by external service which will probably be able to send you an SMS or make a phone call.

That being said, if you want to still send emails, you need to store the last error time in a separate file, and before sending a mail read the file and check when was the last time a mail was sent. The important detail here is that the file need to be writable by the web server. It is probably a good idea to locate it outside of the web root on your server.

share|improve this answer
    
Thanks.. I didn't consider an external monitoring service. I'll look in to that. But, thanks for the response. –  Mark Bubel Mar 7 '13 at 0:18
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.