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.

1 Star2 Stars3 Stars4 Stars5 Stars (3 votes, average: 3.33 out of 5)
Loading ... Loading ...

24 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. Nico Says:

    Awesome script! Is it possible to have them enter what site they want?

  9. jin Says:

    Do you have a script that will check other services aside from http?

  10. locksmith leicester Says:

    I’m getting a fatal error when i try to create a new page on WP. I think it has something to do with the new WP update. Is anybody else having a equivalent issue? Know how it can be fixed???? Cheers.

  11. 30 ml essential oil bottles Says:

    Hey There. I found your blog using msn. This is a very well written article. I will be sure to bookmark it and return to read more of your useful information. Thanks for the post. I will certainly return.

  12. Best Anti Aging Cream For Says:

    Between me and my husband we’ve owned more MP3 players over the years than I can count, including Sansas, iRivers, iPods (classic & touch), the Ibiza Rhapsody, etc. But, the last few years I’ve settled down to one line of players. Why? Because I was happy to discover how well-designed and fun to use the underappreciated (and widely mocked) Zunes are.

  13. authentic sport jerseys Says:

    WONDERFUL Post.thanks for share..more wait .. ??

  14. plr articles Says:

    magnificent publish, very informative. I wonder why the opposite experts of this sector don’t realize this. You should proceed your writing. I am sure, you have a huge readers’ base already!

  15. chaoyang acrobatic show Says:

    10611062106310641065106610671068106910701071107210731074107510761077107810791080

  16. chanel outlet Says:

    Sorry for the huge review,coach outlet store online but I’m really loving the new Zune, and hope this, as well as the excellent reviews some other people have written, will help you decide if it’s the right choice for you.

  17. elementy kute Says:

    It’s the best time to make some plans for the future and it’s time to be happy. I’ve read this post and if I could I want to suggest you some interesting things or tips. Maybe you could write next articles referring to this article. I wish to read more things about it!

  18. occaxPake Says:

    karen millen store

    online sale clothing

    caren miller

  19. Donnie Janick Says:

    Katherine Heigl has also recently been by using a heated vacation rear, contrary to she is extremely powerful tan, possibly she’s been a significant use of Journey Tropez. Most definitely i’ll are convinced the latter. people pleased with in instances where rrnside a white colored golden, the fact is that Catherine is naughty and F Nicole von Furstenberg shirts or dresses right before nov 2008 election. bare program if your attire of cotton, yarn louis vuitton galliera azur some grilling with charcoal dog pen cover in what is a up to date organza and looking after coloration struggle.

  20. seo software Says:

    Well I truly liked studying it. This article provided by you is very practical for proper planning.

  21. Moncler Jackets Says:

    moncler-jacketsale.org is a famous Moncler outlet online shop which sell directly Moncler Coats, Tee-Shirt, Shoes, and other Moncler Clothing For women and Men Moncler Jackets Onsale 50-80% off, Directly Factory Delivery. Non-tax, Free World Shipping! Buy Now !!!

  22. coach outlet Says:

    you have a great sites it! do you want to make a few invite posts on my blogs?

  23. birthday quotes Says:

    Thanks for sharing WLScripting.com » Website uptime check with us keep update bro love your article about WLScripting.com » Website uptime check .

  24. Tod Baisten Says:

    Thanks a bunch for sharing this with all of us you actually know what you are talking about! Bookmarked. Kindly also visit my website =). We could have a link exchange agreement between us!

geovisitors