The SitePoint Forums have moved.

You can now find them here.
This forum is now closed to new posts, but you can browse existing content.
You can find out more information about the move and how to open a new account (if necessary) here.
If you get stuck you can get support by emailing forums@sitepoint.com

If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Using PHP To Send Email When a Site is Down

Does anyone have an idea for a way to use PHP to check if a sight is down (maybe by doing a ping periodically) and then send an email if it is down? I have a panicky site owner who wants something to constantly check to see if his site is down and get a notification when it is.

I am not a PHP master but I would've thought this wouldn't be too difficult to pull off with PHP. I mean there would be 2 parts to the PHP script. First, do a ping or some other check on the server. Second, if the value returned indicates a problem, send an email.

Another reason I would like to try to do this through PHP is the owner is not too big on paying for 3rd party services.

Well you need to run the script off the server as if the server is down, you cant run the script. You can ping or telnet or use snmp to check the server status. I would recommend telnet as you can do services that way. Unless it denies telnet access to the specific ports.

Does anyone have an idea for a way to use PHP to check if a sight is down (maybe by doing a ping periodically) and then send an email if it is down? I have a panicky site owner who wants something to constantly check to see if his site is down and get a notification when it is.

There is definitly lots of ways to do this..

setup a file on your main server and have a cron job call this file once a minute, if your hosting doesn't support cron use http://www.webbasedcron.com

1 other thing, if the site is hosted on your server [if you have a reseller account] you couldn't really have the script running from yours becuase if his site goes down, then your site goes down as well - or is my thinking wrong here?

Anyone have any ideas what might be going wrong? I have tested the servercheck.php by loading it up in the browser and it does execute through that method. Also my PHP is installed as a CGI, thus the "#!/usr/local/bin/php -q".

Sillysoft, good troubleshooting ideas, but no luck here. I tried the first 2 approaches and it still didn't work. Then I changed the permissions by doing chmod 777 on checkserver.php and still nothing. Any other ideas?

Sheesh what kind of miracle does it take to get cron and php to work together? I had been trying it on Linux where PHP was run as a CGI and then I tried it on BSD where PHP is an Apache module and still no execution of the PHP script! I am running out of ideas. Any PHP or Unix gurus out there have any suggestions?

It might be worth replacing "/home/example/example.com/temp/servercheck.php" in your cron with "http://example.com/servercheck.php." I've had luck running scripts on remote servers like that, but not sure about on the same box.

Well I forgot what the -q is, but >> /dev/null means your telling the job to report all output/errors to /dev/null. The script will run just fine but if you have any output from the script tt will not show it as it throws it to /dev/null. The >> /dev/null problem did not resolve your issue, the -q resolved your issue.