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.
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 5)
September 26th, 2006 at 5:22 pm
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?
September 26th, 2006 at 5:23 pm
also…. cool comment tool, how can I get it for my site? is it ajax?
September 27th, 2006 at 6:15 pm
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!
November 20th, 2006 at 11:32 pm
thanks, will try again and also thanks for link to comments tool. downloaded it and ready to try.
April 1st, 2007 at 5:15 pm
One of the best locations I\’ve come across lately!!! Definately a permanent bookmark!
June 9th, 2008 at 3:32 pm
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…
September 23rd, 2008 at 9:00 pm
Glad to hear that this script is being used.
October 5th, 2008 at 3:09 am
naked blonde amatures