Mar
How long can you keep it up?
Update:
Thanks to the comment from one dollar a day, I discovered that for sites that redirect www to non-www, and vice-versa, the script didn’t work. The following code does, by testing both the www, and the non-www version:
$url = “someurl.com”;
$url1=’http://www.’ .$url;
$url2=’http://’ .$url;
@$results = get_headers($url1, 1);
if (strstr($results[0], ‘200′))
{
$status = “OK”;
}
else
@$results = get_headers($url2, 1);
if (strstr($results[0], ‘200′))
{
$status = “OK”;
}
else
{
$status = “borked”;
}
echo $url. ‘ is ‘ .$status;
============end update==============
Just discovered a nifty trick new in PHP5 that allows you to check the status of a site.
Here’s the code:
<? $url = ’someurl.com’;
$xurl=’http://’ .$url;
@$results = get_headers($xurl, 1);
if ($results[0] == ‘HTTP/1.1 200 OK’) {
echo $url. ‘ is <font color=”green”><b>online</font></b><br>’;
} else {
echo $url. ‘ is <font color=”red”><b>down</font></b><br>’;
}
?>
Pretty simple I reckon. You can see it in action here
What does this mean for businesses like siteuptime I wonder? I would imagine that it would be fun to set up a monitoring service like this. (Siteuptime only offer four monitoring stations as well - 3 in the US, one in the UK.)
This could be fun, we could set up a monitoring service with hundreds of test points!
, super redundancy over dozens of datacentres, the mind boggles…
11 comments so far
That’s quite a nice bit of PHP there Stu. Haven’t looked at anything like that before (PHP is so vast!). That could be very handy in conjunction with a CRON job. If the site is down an email can be sent off. Of course that’s ensuring the server that the script is on doesn’t go down!
I thought the same thing Sarah.
I have a “console” page, which tells me pretty much everything I need to know about my empire (keyword rankings for certain sites, rss feeds I keep an eye on, that sort of stuff (If you look through my tools section, you’ll get a pretty good idea of what it does. ;-))
I want to use this sort of thing to monitor uptime across my sites, but as you say, there’s little point running this sort of thing on the same server the rest of your sites are on.
Methinks I might grab a cheap shared hosting account somewhere else, so I can set up something like this. I have a question though - I know nothing about how cron jobs work. Is it possible to create cron jobs through a html/php form? It would be sweet if you could just go to a page, enter a URL and an email address, and the cron was set up automatically.
Cheers
Stu
Never mind Sarah, I think I worked a way you could do this:
Each time someone comes along and and fills in the form, the details are entered into a text file or database.
The Cron is set to run the check script every 15 minutes or whatever, and when the script runs, it loops through all the accounts in the database one by one.
Sometimes the most complex things come to me straight away, whilst the simplest ones seem to elude me…. ![]()
I just put google.com into your example but it says it’s down! Why would that happen? Seems ok for other sites I tried.
@ ODAD - It doesn’t follow redirects - if you type google.com in your address bar, google redirects you to www.google.com, but this function just sees that there’s nothing at google.com, so returns a negative result.
I spent some time last night writing part of a script like I mentioned in the earlier comment. I’ve got to work out a way that if the initial response is negative, the script tries the other option. (I’m a php noob, so it might take me a while!
)
Thanks for the script. I’m going to give this a try.
The Cron is set to run the check script every 15 minutes or whatever, and when the script runs, it loops through all the accounts in the database one by one.
Thanks for the information.
[...] threw up a little script the other day which checks a given URL, and tells you whether it’s up or [...]
Thank for the script. Work well as a cron job on my computer. ![]()
I think you may need update script in http://pimpmypagerank.com/tools/sitechecker/
It still say google.com down.
Nice script. I will use it in future with other projects. At the moment I don’t need it, but I saved it for when I need it, but can’t find it. if someone knows what i mean.
Leave a Comment:
G'day!
-
feel the feed!
-
Recent Posts
Top Commenters
-
Pimp My Page Rank
It's all about:
-
Friends and well wishers:
SEO Bloggers
Archives