Website uptime check
By: Daniel

Do you ever want to check many websites to see if they are up or not? This code can help you check multiple sites all from one page.

<?php
function prepWWW($url) {
  $replace = array("http://" => "", "www." => "");
  foreach($replace as $toReplace=>$replaceWith) {
    $url = str_replace($toReplace, $replaceWith, $url);
  }
  $parts = explode("/", $url);
  $newURL = strip_tags(addslashes($parts[0]));
  return $newURL;
}

$site = prepWWW("www.wlscripting.com");
$check = @fsockopen($site, 80);

if($check) {
  echo "$site is up";
} else {
  echo "$site is down";
}
?>

First off we create the prepWWW function. This just prepares the domain name for usage with fsockopen(). We strip out all extra parts to the url so we only get the main domain like: wlscripting.com NOT http://www.wlscripting.com

Then we just check the website with fsockopen() on port 80, which is the port that Apache or IIS runs on usually unless you configured it differently. This 80 can be changed to any other port number to checking other services like: FTP 21, cPanel 2082, WHM 2086, and so on.

3 Votes | Average: 3.33 out of 53 Votes | Average: 3.33 out of 53 Votes | Average: 3.33 out of 53 Votes | Average: 3.33 out of 53 Votes | Average: 3.33 out of 5 (3 votes, average: 3.33 out of 5)
Loading ... Loading ...
del.icio.us:Website uptime check digg:Website uptime check spurl:Website uptime check wists:Website uptime check simpy:Website uptime check newsvine:Website uptime check blinklist:Website uptime check furl:Website uptime check reddit:Website uptime check fark:Website uptime check blogmarks:Website uptime check Y!:Website uptime check smarking:Website uptime check magnolia:Website uptime check segnalo:Website uptime check

8 Responses to “Website uptime check”

  1. brandon Says:

    I think this is great, but when trying to put two copies on it to monitor more than one site it crashes the second instance on the page. How can this be used to monitor many sites from one page?

  2. brandon Says:

    also…. cool comment tool, how can I get it for my site? is it ajax?

  3. Daniel Says:

    Running multiple copies works just fine. What is your setup and how is your script setup?

    Here is a demo of this running with multiple sites being checked:
    Demo: http://demo.wlscripting.com/tutorial30/prepWWW.php
    Source: http://demo.wlscripting.com/tutorial30/prepWWW.phps

    The comment tool is: http://www.mikesmullin.com/2006/06/05/ajax-comments-20/

    Post back if you still need help!

  4. brandon Says:

    thanks, will try again and also thanks for link to comments tool. downloaded it and ready to try.

  5. Phillip Says:

    One of the best locations I\’ve come across lately!!! Definately a permanent bookmark!

  6. Rivo99 Says:

    Daniel - Thanks for this script! I find myself using it on my iPhone each morning as I’m driving to work. I made a few modifications to add a green “Check” and a red “X” depending on the site being up or down. Like I said I use this script mostly on my iphone and with the display being smaller, the graphics help me take a quick glance and know if I have a site in trouble or not… Here are the simple mods that I made:

    if($check) {
    echo “$site is up”;
    } else {
    echo “$site is down”;

    Hope this helps anyone else using a smart phone…

  7. Daniel Says:

    Glad to hear that this script is being used.

  8. mjqhcte Says:

    naked blonde amatures

Leave a Reply

eXTReMe Tracker
geovisitors