Here's a quick piece of code that will do what you'd like. You'd just need to set a cron to hit the script every 5 minutes.
PHP Code:
<?php
// the URL you want to keep tabs on
$url = 'http://www.somewebsite.com';
// if not available, send email
if ( url_exists( $url ) === FALSE )
{
$to = 'my@email.com';
$subj = $url . ' is down!';
$msg = $url . ' was tested at ' . date( 'Y-m-d H:i:s' ) . ' and was inaccessible.';
@mail( $to, $subj, $msg );
}
/**
* url_exists()
* Checks for the validity of a given URL
*
* @param string The http[s] URL you're checking for
* @return bool TRUE if online; FALSE if not; NULL if not an http(s):// URL
*/
function url_exists( $strURL = NULL )
{
if ( !preg_match( '/^http(s?):\/\//i', $strURL, $m ) )
return NULL;
@$ch = curl_init();
curl_setopt( $ch, CURLOPT_URL, $strURL );
curl_setopt( $ch, CURLOPT_BINARYTRANSFER, 1 );
curl_setopt( $ch, CURLOPT_HEADERFUNCTION, 'curlHeaderCallback' );
curl_setopt( $ch, CURLOPT_FAILONERROR, 1 );
curl_setopt( $ch, CURLOPT_TIMEOUT, 5 );
// https?
if ( $m[1] == 's' )
curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, 0 );
@curl_exec( $ch );
$intReturnCode = curl_getinfo( $ch, CURLINFO_HTTP_CODE );
curl_close( $ch );
return ( $intReturnCode == 200 OR $intReturnCode == 302 OR $intReturnCode == 304 ) ? TRUE : FALSE;
}
?>