06

Apr

Check whether multiple sites are up or down

Posted by stuart as php, site statistics

I threw up a little script the other day which checks a given URL, and tells you whether it’s up or down.

I’m actually using the script to check multiple sites, all in one job, and I thought I’d post it here in case any of you might find it useful.

Throw a text file called urls.txt with your URL’s in it in the same folder as the script, and run the script.

Here’tis:

<?

$filename = ‘urls.txt’;

$fp = @fopen($filename, ‘r’);

if ($fp) {

$array = explode(”\n”, fread($fp, filesize($filename)));

foreach ($array as $url) {
$url = str_replace(”http://”, “”, $url);

$url = str_replace(”http://www.”, “”, $url);

$url1=’http://www.’ .$url;

$url2=’http://’ .$url;

@$results = get_headers($url1, 1);

if (strstr($results[0], ‘200′))

{

$status = “Rockin!”;

}

else

@$results = get_headers($url2, 1);

if (strstr($results[0], ‘200′))

{

$status = “Rockin!”;

}

else

{

$status = “Borked”;

}

echo $url. ‘ is ‘ .$status. ‘<br>’;

}

}

?>

3 comments so far

Handy script. I work on a lot of sites, and one of my host dies on me all the time. Will be useful.

Oooh… I like that! We have an admin who is always asleep at the switch and usually find out if a site has issues from a customer!

This will be very useful indeed. THANKS A GAZILLION!

That’s very helpful. Instead of me manually checking my 30+ sites, I can set the checking to cruise control.

Leave a Comment:

Name (required)
Mail (will not be published) (required)
Website
Message