Membership is FREE, giving all registered users unlimited access to every Acorn Domains feature, resource, and tool! Optional membership upgrades unlock exclusive benefits like profile signatures with links, banner placements, appearances in the weekly newsletter, and much more - customized to your membership level!

Are your sites up or down [code to tell]

Status
Not open for further replies.
Joined
Jan 19, 2007
Posts
2,207
Reaction score
47
A few weeks ago I didn't notice that one of my site's went down. It was down for 3 weeks. I was busy and didn't check it.

It went down for me not paying a renewal for a domain that I wanted to expire. The registrar changed the DNS on all domains in the account (I guess because of non-payment although I hadn't had notification because there was an old email on the account).

Basically, I wasn't on top of things and I got screwed. The website that was down for 3 weeks has of course been killed by Google. It was on the first page bringing in about $100 of affiliate income a month....

So since I found out I wanted to create a script (on a webpage) that will be my homepage and tell me if my sites are running ok.

I'm sure it can be improved (design/accuracy). There may be false negatives. I've pasted it below as it might help some people keep an eye on your sites.

basically copy and paste the code below into a new file (call it something like sitecheck.php) then upload it to your a single site. You can then access the status of your websites by going to your domain.com/sitecheck.php

You should of course change the websites in the code to your websites and also delete the related lines of code if you have fewer than 31 sites (or add more, if you have more)

PHP:
<?php
echo 'Checking sites...<br />';

function Visit($url){
       $agent = "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)";$ch=curl_init();
       curl_setopt ($ch, CURLOPT_URL,$url );
       curl_setopt($ch, CURLOPT_USERAGENT, $agent);
       curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
       curl_setopt ($ch,CURLOPT_VERBOSE,false);
       curl_setopt($ch, CURLOPT_TIMEOUT, 5);
       curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, FALSE);
       curl_setopt($ch,CURLOPT_SSLVERSION,3);
       curl_setopt($ch,CURLOPT_SSL_VERIFYHOST, FALSE);
       $page=curl_exec($ch);
       //echo curl_error($ch);
       $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
       curl_close($ch);
       if($httpcode>=200 && $httpcode<300) return true;
       else return false;
}

$url1 = "http://www.google.co.uk/"; 	
$url2 = "http://www.msn.com/"; 	
$url3 = "http://www.bbc.co.uk/"; 	
$url4 = "http://www.acorndomains.co.uk/"; 	
$url5 = "http://www.yahoo.co.uk/"; 	
$url6 = "http://www.domain.com/"; 	
$url7 = "http://www.website.co.uk/"; 	
$url8 = "http://www.hello.co.uk/"; 	
$url9 = "http://www.wowee.co.uk/"; 	
$url10 = "http://www.cnn.info/"; 	
$url11 = "http://www.egg.com/"; 
$url12 = "http://www.starbucks.com/"; 	
$url13 = "http://www.apple.co.uk/"; 	
$url14 = "http://www.domainlore.co.uk/"; 	
$url15 = "http://www.yourdomain.com/"; 	
$url16 = "http://www.bored.org.uk/"; 	
$url17 = "http://www.i.co.uk/"; 	
$url18 = "http://www.am.co.uk/index.php"; 	
$url19 = "http://www.just.com/"; 	
$url20 = "http://www.blanking.co.uk/"; 	
$url21 = "http://www.out.com/"; 
$url22 = "http://www.my.com/"; 	
$url23 = "http://www.domains.org/"; 	
$url24 = "http://www.from.com/"; 
$url25 = "http://www.this.com/"; 	
$url26 = "http://www.list.org.uk/"; 	
$url27 = "http://www.of.com/"; 
$url28 = "http://www.websites.co.uk/"; 	
$url29 = "http://www.bye.co.uk/"; 
$url30 = "http://www.for.org/"; 	
$url31 = "http://www.now.com/"; 

if (Visit("$url1"))	echo "<a href='$url1'/>$url1</a>"." OK"."<br />";	else     echo "<font color='red'>$url1 DOWN</font>"."<br />";
if (Visit("$url2"))	echo "<a href='$url2'/>$url2</a>"." OK"."<br />";	else     echo "<font color='red'>$url2 DOWN</font>"."<br />";
if (Visit("$url3"))	echo "<a href='$url3'/>$url3</a>"." OK"."<br />";	else     echo "<font color='red'>$url3 DOWN</font>"."<br />";
if (Visit("$url4"))	echo "<a href='$url4'/>$url4</a>"." OK"."<br />";	else     echo "<font color='red'>$url4 DOWN</font>"."<br />";
if (Visit("$url5"))	echo "<a href='$url5'/>$url5</a>"." OK"."<br />";	else     echo "<font color='red'>$url5 DOWN</font>"."<br />";
if (Visit("$url6"))	echo "<a href='$url6'/>$url6</a>"." OK"."<br />";	else     echo "<font color='red'>$url6 DOWN</font>"."<br />";
if (Visit("$url7"))	echo "<a href='$url7'/>$url7</a>"." OK"."<br />";	else     echo "<font color='red'>$url7 DOWN</font>"."<br />";
if (Visit("$url8"))	echo "<a href='$url8'/>$url8</a>"." OK"."<br />";	else     echo "<font color='red'>$url8 DOWN</font>"."<br />";
if (Visit("$url9"))	echo "<a href='$url9'/>$url9</a>"." OK"."<br />";	else     echo "<font color='red'>$url9 DOWN</font>"."<br />";
if (Visit("$url10"))	echo "<a href='$url10'/>$url10</a>"." OK"."<br />";	else     echo "<font color='red'>$url10 DOWN</font>"."<br />";
if (Visit("$url11"))	echo "<a href='$url11'/>$url11</a>"." OK"."<br />";	else     echo "<font color='red'>$url11 DOWN</font>"."<br />";
if (Visit("$url12"))	echo "<a href='$url12'/>$url12</a>"." OK"."<br />";	else     echo "<font color='red'>$url12 DOWN</font>"."<br />";
if (Visit("$url13"))	echo "<a href='$url13'/>$url13</a>"." OK"."<br />";	else     echo "<font color='red'>$url13 DOWN</font>"."<br />";
if (Visit("$url14"))	echo "<a href='$url14'/>$url14</a>"." OK"."<br />";	else     echo "<font color='red'>$url14 DOWN</font>"."<br />";
if (Visit("$url15"))	echo "<a href='$url15'/>$url15</a>"." OK"."<br />";	else     echo "<font color='red'>$url15 DOWN</font>"."<br />";
if (Visit("$url16"))	echo "<a href='$url16'/>$url16</a>"." OK"."<br />";	else     echo "<font color='red'>$url16 DOWN</font>"."<br />";
if (Visit("$url17"))	echo "<a href='$url17'/>$url17</a>"." OK"."<br />";	else     echo "<font color='red'>$url17 DOWN</font>"."<br />";
if (Visit("$url18"))	echo "<a href='$url18'/>$url18</a>"." OK"."<br />";	else     echo "<font color='red'>$url18 DOWN</font>"."<br />";
if (Visit("$url19"))	echo "<a href='$url19'/>$url19</a>"." OK"."<br />";	else     echo "<font color='red'>$url19 DOWN</font>"."<br />";
if (Visit("$url20"))	echo "<a href='$url20'/>$url20</a>"." OK"."<br />";	else     echo "<font color='red'>$url20 DOWN</font>"."<br />";
if (Visit("$url21"))	echo "<a href='$url21'/>$url21</a>"." OK"."<br />";	else     echo "<font color='red'>$url21 DOWN</font>"."<br />";
if (Visit("$url22"))	echo "<a href='$url22'/>$url22</a>"." OK"."<br />";	else     echo "<font color='red'>$url22 DOWN</font>"."<br />";
if (Visit("$url23"))	echo "<a href='$url23'/>$url23</a>"." OK"."<br />";	else     echo "<font color='red'>$url23 DOWN</font>"."<br />";
if (Visit("$url24"))	echo "<a href='$url24'/>$url24</a>"." OK"."<br />";	else     echo "<font color='red'>$url24 DOWN</font>"."<br />";
if (Visit("$url25"))	echo "<a href='$url25'/>$url25</a>"." OK"."<br />";	else     echo "<font color='red'>$url25 DOWN</font>"."<br />";
if (Visit("$url26"))	echo "<a href='$url26'/>$url26</a>"." OK"."<br />";	else     echo "<font color='red'>$url26 DOWN</font>"."<br />";
if (Visit("$url27"))	echo "<a href='$url27'/>$url27</a>"." OK"."<br />";	else     echo "<font color='red'>$url27 DOWN</font>"."<br />";
if (Visit("$url28"))	echo "<a href='$url28'/>$url28</a>"." OK"."<br />";	else     echo "<font color='red'>$url28 DOWN</font>"."<br />";
if (Visit("$url29"))	echo "<a href='$url29'/>$url29</a>"." OK"."<br />";	else     echo "<font color='red'>$url29 DOWN</font>"."<br />";
if (Visit("$url30"))	echo "<a href='$url30'/>$url30</a>"." OK"."<br />";	else     echo "<font color='red'>$url30 DOWN</font>"."<br />";
if (Visit("$url31"))	echo "<a href='$url31'/>$url31</a>"." OK"."<br />";	else     echo "<font color='red'>$url31 DOWN</font>"."<br />";


?>
 
Thanks JMOT - I wish you had told me about it a year ago ! (or even a month ago)

I'll check it out.

Update: Pingdom does seem pretty cool and reliable - it'll just cost me over $40/month to keep an eye on 30+ sites.
Of course it's awesome because it sends out SMS alerts, and lets you know even if you don't visit a specific webpage.
 
Last edited:
This might be a better solution :) :

PHP:
function status(){
	error_reporting(0);
	
	$domains = array('test.co.uk', 'jkdhskhd.co.uk');
	
	$statuses = array();
	foreach($domains as $domain){
		$file = fsockopen ($domain, 80, $errno, $errstr, 2);
		if(!$file){ $status = -1; }else{ $status = 0; fclose($file); }
		array_push($statuses, array($domain, $status));
	}
		
	foreach($statuses as $status){
		if($status[1] == -1){
			$output .= "<a href='http://www." . $status[0] . "' target='_blank'>" . $status[0] . " is down</a><br />";
		}else{
			$output .= $status[0] . " is ok<br />";
		}
	}
		
	return $output;
}

Then put this between the <body> and </body> tags:
PHP:
<?php echo status(); ?>

Hope this helps someone!

Craig
 
Thanks SV - I should credit the source that I got part of the code above - can't remember atm.

Your code looks shorter and maybe easier - can you educate me on why else it's better. I'm still learning PHP and if there are efficiencies it can really help me (server process overload happens a fair bit on shared hosting)
 
Thanks SV - I should credit the source that I got part of the code above - can't remember atm.

Your code looks shorter and maybe easier - can you educate me on why else it's better. I'm still learning PHP and if there are efficiencies it can really help me (server process overload happens a fair bit on shared hosting)
Sure :)

The code I posted simply checks port 80 through PHP's fsockopen function. If port 80 is available, the site is up, if not, it's down. This would be much quicker than the code you posted as that example uses CURL which would basically spider the actual page of the website, therefore loading all content on the page, which would in turn make it slower. This would be much more noticeable when more sites are added.

Hope this helps, if you have any specific questions just let me know

Kind Regards,

Craig
 
Thanks Craig. I love php and have made some cool stuff happen with it. Trouble is I always recycle other people's snippets of code and don't really learn how to to it (and forget how I did it...)

I patched together a free sms service (free to visitors, but cost me a few p/txt) and so I think I can connect your code to my sms service api and be sent a message if a website is down... (another project for the pile)
 
Status
Not open for further replies.

The Rule #1

Do not insult any other member. Be polite and do business. Thank you!

Members online

Premium Members

New Threads

Domain Forum Friends

Our Mods' Businesses

*the exceptional businesses of our esteemed moderators
General chit-chat
Help Users
  • No one is chatting at the moment.
      There are no messages in the current room.
      Top Bottom