• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 230
  • Last Modified:

Monitor Website - Can this be done?

Hello,

I would like to be able to create a new website (ideally with PHP or similar) where I can enter a URL (usually the root address - i.e. http://www.website.com) and I would like to see if a page is returned on that URL. All I need to really know is that a page exists - I suppose I am just looking for an HTTP response of 200?

Can this be done. I would like a page to list a number of URL and have a green mark by them if a 200 OK HTTP response is received and an Amber Mark next to it should anything else in the HTTP response be received. I would like to check pages are being served (not that they are working correctly or anything like that just that the page is being served from the server).

Is this something relatively easy that can be done and is the best thing to look for in this instance. Any other recommendations or approaches to this would be welcome.

Regards,

GISVPN
0
gisvpn
Asked:
gisvpn
4 Solutions
 
sshah254Commented:
A simple "open" function should suffice - check the examples here - http://php.net/manual/en/function.fopen.php

SS
0
 
edster9999Commented:
As above you can open webpages inside PHP and check the results very easily.
...but...

if this is for public use (ie check your website is working) then be careful as it can be used by people to perform a DOS (Denyal of service) attack on a seperate web site.  They use your page to request thousands of pages from one site and watch it slow down or even crash.
Think about adding a block that counts sites and blocks it after a while.
(oh and this type of site already exists on the internet)

If it is for your own use then check mon.d
www.google.com/search?q="mon.d"+kernel
0
 
gisvpnAuthor Commented:
Hi sshah254 - can the fopen look for the response 200 at all?

edster9999 - thanks for the post.
0
 
xtermCommented:
The PHP function fsockopen honors http response codes.  Here's a little simple program that i put together that will do exactly what you need:
<?php

$sites_monitored=array("www.yahoo.com", "www.google.com","failonpurpose.com1");

echo "<html><table border=1>\n";
echo "<tr><td>Site Name</td><td>Debug</td><td>Status</td><tr>";

for ($i=0; $i<sizeof($sites_monitored); $i++) {
  $site=$sites_monitored[$i];
  $fp=fsockopen("$site", 80, $errno, $errstr, 3);
  if (!$fp) {
      $debug="$errstr ($errno)<br>\n";
      $status="red";
  } else {
      $debug="Success";
      $status="green";
      fclose($fp);
  }
  echo "<tr><td>$site</td><td>$debug</td><td bgcolor=$status>&nbsp;</td></tr>\n";
}

echo "</table></html>\n";

?>

Open in new window

0
 
Ray PaseurCommented:
Here is how I would do it... Try the output from:
http://www.laprbass.com/RAY_monitor_website.php

Best regards, ~Ray
<?php // RAY_monitor_website.php
error_reporting(E_ALL);


// DEMONSTRATE HOW AN INDIVIDUAL WEB SITE MONITOR WORKS


// A WEB SITE TO MONITOR - THIS COULD COME FROM THE URL VIA $_GET
$url = 'www.degage.com';

// COMMONLY USED PORT NUMBERS
// SEE: http://www.iana.org/assignments/port-numbers
// SEE: http://browntips.com/cpanel-and-whm-port-numbers/
$ports["HTTP"]     =    80;
$ports["FTP"]      =    21;
$ports["SSH"]      =    22;
$ports["TELNET"]   =    23;
$ports["SMTP"]     =    25;
$ports["DNS"]      =    53;
$ports["MYSQL"]    =  3306;
$ports["CPANEL"]   =  2082;
$ports["CPANEL-S"] =  2083;
$ports["WHM"]      =  2086;
$ports["WHM-S"]    =  2087;
$ports["POP3"]     =   110;
$ports["IMAP"]     =   143;
$ports["BOGUS"]    = 11111; // THIS IS EXPECTED TO FAIL

// THE RESULTS SET
$errno = $errstr = array();

// THE TIME TO ALLOW FOR CONNECTION
$timex = 1;

// TEST EACH OF THE PORTS - SEE http://php.net/manual/en/function.fsockopen.php
foreach ($ports as $port_name => $port_number)
{
    $fp
    = @fsockopen // @MAKE ERRORS SILENT
    ( $url
    , $port_number
    , $errno[$port_name]
    , $errstr[$port_name]
    , $timex
    )
    ;
}

// REPORT WHAT HAPPENED IN EASY-TO-READ FORMAT
echo "<pre>";

// OPTIONAL
// echo 'WHO: ' . exec('whoami') . PHP_EOL;

echo "URL: $url TIME: $timex" . PHP_EOL;
foreach ($errno as $port_name => $error_number)
{
    if (!$error_number)
    {
        echo PHP_EOL . "OK: $port_name $ports[$port_name]";
    }
    else
    {
        echo PHP_EOL . "ERROR $error_number: $port_name $errstr[$port_name] ON PORT $ports[$port_name]";
    }
}

// TEST WWW RESPONSE WITH CURL
$x = my_curl('http://' . $url . '/anything_will_do_here');
if (!$x)
{
    echo PHP_EOL . "ERROR WWW Response: FAIL";
}
else
{
    echo PHP_EOL . "WWW RESPONSE OK";
}

// A FUNCTION TO RUN A CURL-GET CLIENT CALL TO A FOREIGN SERVER
function my_curl($url, $timeout=1, $error_report=FALSE)
{
    $curl = curl_init();

    // HEADERS AND OPTIONS APPEAR TO BE A FIREFOX BROWSER REFERRED BY GOOGLE
    $header[] = "Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5";
    $header[] = "Cache-Control: max-age=0";
    $header[] = "Connection: keep-alive";
    $header[] = "Keep-Alive: 300";
    $header[] = "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7";
    $header[] = "Accept-Language: en-us,en;q=0.5";
    $header[] = "Pragma: "; // BROWSERS USUALLY LEAVE BLANK

    // SET THE CURL OPTIONS - SEE http://php.net/manual/en/function.curl-setopt.php
    curl_setopt( $curl, CURLOPT_URL,            $url  );
    curl_setopt( $curl, CURLOPT_USERAGENT,      'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1.6) Gecko/20091201 Firefox/3.5.6'  );
    curl_setopt( $curl, CURLOPT_HTTPHEADER,     $header  );
    curl_setopt( $curl, CURLOPT_REFERER,        'http://www.google.com'  );
    curl_setopt( $curl, CURLOPT_ENCODING,       'gzip,deflate'  );
    curl_setopt( $curl, CURLOPT_AUTOREFERER,    TRUE  );
    curl_setopt( $curl, CURLOPT_RETURNTRANSFER, TRUE  );
    curl_setopt( $curl, CURLOPT_FOLLOWLOCATION, TRUE  );
    curl_setopt( $curl, CURLOPT_TIMEOUT,        $timeout  );

    // RUN THE CURL REQUEST AND GET THE RESULTS
    $htm = curl_exec($curl);

    // ON FAILURE HANDLE ERROR MESSAGE
    if ($htm === FALSE)
    {
        if ($error_report)
        {
            $err = curl_errno($curl);
            $inf = curl_getinfo($curl);
            echo "CURL FAIL: $url TIMEOUT=$timeout, CURL_ERRNO=$err";
            var_dump($inf);
        }
        curl_close($curl);
        return FALSE;
    }

    // ON SUCCESS RETURN XML / HTML STRING
    curl_close($curl);
    return $htm;
}

Open in new window

0

Featured Post

Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now