944,135 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 4045
  • PHP RSS
Jul 1st, 2005
0

Send mail on MYSQL connection failure

Expand Post »
Hi there,
I was trying to get a script working that will fire me an email when my database cannot be connected to. This is what I have and I'm wondering if it looks right to you php experts.

$conn = mysql_connect ($server,$user,$pass) or die(mail("$SendToEmail", "$yoursubject", $emailtext . mysql_error(), "From: $email"));


Also, does anyone know how to have an email sent when the appache services stop running (i.e. website unavailable). I'm trying to track how many times my isp's services fail. I plan on setting up a cronjob that will run the above line every 5 minutes along with one that checks to see if my site is still accessible.

Thank you for your time and brain power!
Last edited by happygeek; May 14th, 2007 at 7:55 am. Reason: Real name removed from post as requested
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Koldar is offline Offline
2 posts
since Jul 2005
Jul 1st, 2005
0

Re: Send mail on MYSQL connection failure

There are some services to check and email you if your website goes down. A partial list: http://www.webhostingtalk.com/showth...hreadid=400382

Also, your PHP code looks right. Have you tried testing it? You can test it by changing your MySQL database info, for instance, so that it cannot connect.
Team Colleague
Reputation Points: 53
Solved Threads: 5
PHP/vBulletin Guru
Gary King is offline Offline
360 posts
since Nov 2003
Jul 3rd, 2005
0

Re: Send mail on MYSQL connection failure

Also read about PHP's error handling abilities...

http://aspn.activestate.com/ASPN/doc...-handling.html
Reputation Points: 11
Solved Threads: 0
Junior Poster in Training
senexom is offline Offline
54 posts
since Jun 2005
Jul 7th, 2005
0

Re: Send mail on MYSQL connection failure

Thank you for the resources. I've checked out the site monitoring services and signed up for a couple of them already. Are any of you familiar with CPanel? I guess that my ultimate goal is to create a script similar to the site monitor that is bundled with CPanel. I'm just not familiar enough with PHP and Apache to know where all of the services and variables are located to tell me when, for example, mail is down or apache itself has stopped running. Are there any other places you might be able to send me to help out with finding a way to monitor those services as well?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Koldar is offline Offline
2 posts
since Jul 2005
Jul 8th, 2005
0

Re: Send mail on MYSQL connection failure

Quote originally posted by Koldar ...
Thank you for the resources. I've checked out the site monitoring services and signed up for a couple of them already. Are any of you familiar with CPanel? I guess that my ultimate goal is to create a script similar to the site monitor that is bundled with CPanel. I'm just not familiar enough with PHP and Apache to know where all of the services and variables are located to tell me when, for example, mail is down or apache itself has stopped running. Are there any other places you might be able to send me to help out with finding a way to monitor those services as well?
If you run a site monitor script on your website to monitor the website, then when the website is down, you won't know, and neither will the script - since the script goes down when the website does!
Team Colleague
Reputation Points: 53
Solved Threads: 5
PHP/vBulletin Guru
Gary King is offline Offline
360 posts
since Nov 2003

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: Tidy up output of ping.
Next Thread in PHP Forum Timeline: PHP + MySQL Problem





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC