Uptime Monitor Script (Noob Friendly)

Status
Not open for further replies.

EnCiPh3r

Banned
Banned
2,499
2009
244
0
PHP:
<?php
   $url = 'yoursite.com';
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_NOBODY, true);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
    curl_exec($ch);
    $retcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    curl_close($ch);
    if (200==$retcode) {
       echo "Site is Up";
    } else {
$to = "Your Email ID Here";
$subject = "Uptime Alert";
$message = "Your website is down take a look @ it";
$from = "uptime@yoursite.com";
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
echo "Current Status : Down";
}
?>

Usage : name it as uptime.php
*/15 * * * * php -q /home/cPanelUsername/public_html/uptime.php


Credits : Original Devs I just combined 2 snippets

Just put the script on cron job of every 15 mins from a free cpanel host and you dont need to spend $10 a month on pingdom
 
14 comments
If you're only going to run this as a cron job, why have echo statements?

Just use
PHP:
 <?php

    $url = 'yoursite.com';
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_NOBODY, true);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
    curl_exec($ch);
    $retcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    curl_close($ch);

    if (200!=$retcode) {
        $to = "Your Email ID Here";
        $subject = "Uptime Alert";
        $message = "Your website is down take a look @ it";
        $headers = "From: uptime@yoursite.com";
        mail($to,$subject,$message,$headers);
    }
?>
 
If you're only going to run this as a cron job, why have an echo statement?

Just use
PHP:
 <?php

    $url = 'yoursite.com';
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_NOBODY, true);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
    curl_exec($ch);
    $retcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    curl_close($ch);

    if (200!=$retcode) {
        $to = "Your Email ID Here";
        $subject = "Uptime Alert";
        $message = "Your website is down take a look @ it";
        $from = "uptime@yoursite.com";
        $headers = "From:" . $from;
        mail($to,$subject,$message,$headers);
    }
?>

Echo Statement is because if he wants to manually check it

Originally i was thinking to make isup.me clone
 
Just something simpler using isup.me, so you know it's reliable, you could also implement a mail feature, with cron to run automatically if you want.

PHP:
<?php

/**
 * This is simple description.
 * 
 * @author Vick Kumar <vickkumar2011@gmail.com>
 * @copyright Seecure.me, 2012
 * @version 1.0
 * @license http://creativecommons.org/licenses/by/3.0/legalcode 
 */


function ismysiteup($website)
{
    if(empty($website))
    {
        return false;
    }
    else
    {
        $fcg = file_get_contents("http://www.isup.me/$website");
        if(strpos($fcg, "It's just you"))
        {
            return $website." is up!";
        }
        else
        {
            return $website." is down!";
        }
    }
}

echo ismysiteup("seecure.me");
?>
 
Status
Not open for further replies.
Back
Top