View Single Post
  #3 (permalink)  
Old 12-29-06, 12:41 AM
Keith's Avatar
Keith Keith is offline
Community Liaison
 
Join Date: Feb 2004
Posts: 1,232
Thanks: 1
Thanked 11 Times in 11 Posts
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$chCURLOPT_URL$strURL );
    
curl_setopt$chCURLOPT_BINARYTRANSFER);
    
curl_setopt$chCURLOPT_HEADERFUNCTION'curlHeaderCallback' );
    
curl_setopt$chCURLOPT_FAILONERROR);
    
curl_setopt$chCURLOPT_TIMEOUT);
    
// https?
    
if ( $m[1] == 's' )
        
curl_setopt$chCURLOPT_SSL_VERIFYPEER);
    @
curl_exec$ch );
    
$intReturnCode curl_getinfo$chCURLINFO_HTTP_CODE );
    
curl_close$ch );
    return ( 
$intReturnCode == 200 OR $intReturnCode == 302 OR $intReturnCode == 304 ) ? TRUE FALSE;
}

?>
__________________
The toxic ZCE
Reply With Quote