PHP is open source scripting language. It\'s widely used to develop web applications.  Home Web Programming PHP Creating a Website / Server Monitoring Script

Creating a Website / Server Monitoring Script


Creating a Website / Server Monitoring ScriptHi there!

I have created a script which allows users to check to see if their server is online. Obviously running this script from the same server and trying to check your server status whilst its down its too clever, so try using an include or iframe from a free hosting company.

Ok, I will be checking my website, jamesterror.net on port 80 which is the HTTP port.

Firstly you'll need to setup your variables.

<?php
$site = 'jamesterror.net';
$port = '80';

This is setting up the site you will be checking and on the port you will be checking.

$check = fsockopen( "$site", "$port", $errno, $errstr, 6 );

This t string $check is now making a connection to a website by using the 'fsockopen' command.

Now we are going to add the part where it say if the server is offline. I have decided to put it in red font so it stands out.

if ( ! $check ){ echo "<font color="#FF0000">Server is Currently Down!</font>";

What this has now done is, if $check (connection to the site) is unable to connect it was echo the message "Server is Currently Down".

We then add the final lines,

}
else{ echo "<font color="#009900">Everything is fine!</font>";}

We now use the ELSE statement, this is so if there is a connection the page will show "Everything is fine!"

Here is the complete script

<?php
$site = 'jamesterror.net';
$port = '80';
$check = fsockopen( "$site", "$port", $errno, $errstr, 6 );
if ( ! $check ){ echo "<font color="#FF0000">Server is Currently Down!</font>";
}
else{ echo "<font color="#009900">Everything is fine!</font>";}
?>

Thank you, James



Author's URL: James
PHP is open source scripting language. It\'s widely used to develop web applications. More PHP Tutorials: Featured Materials | Fresh Materials | More PHP Tutorials at LearnPHP.org

Reader's comments
comments personal loans December 22, 2011 says:
If you want to buy a car, you will have to receive the credit loans. Moreover, my father usually utilizes a student loan, which occurs to be the most firm.
Reply
comments SHERYLLeblanc July 07, 2011 says:
I think that to get the <a href=" loans</a> from banks you should present a great reason. Nevertheless, once I've received a auto loan, just because I was willing to buy a building.
Reply
comments Vlad August 25, 2010 says:
heres a sweet mod to it.

//check servers

$servers = array(1 => "sadf.kasdjfl.com",
3 => "sadf.com",
4 => "mail.monkey.com",
5 => "moreserver.com",
6 => "Server5.com",
7 => "Server3.com",
8 => "Server10.com");


print "Server port 80 check <hr>";

foreach($servers as $key => $value){

$site = $value;
$port = '80';
$check = fsockopen( $site, $port, $errno, $errstr, 6 );
if (!$check){
echo "<font color="#FF0000">".$value.&

Reply
comments Jonessie July 05, 2007 says:
Um, one does apologise for being a pain in the butt, I found an error in your code, nothing serious just when you are using tables or fonts you cannot use "" the same as the script. example "<font color="#FFF0000"></font>"; this will produce an error. Whilst using '<font color="#FFF0000"></font>'; will be fine.

I tinckered with your code a little, because it was a little cluttered.

[code]<?php
$site = 'yourwebsite.com';
$port = '80';
$check = fsockopen("$site", "$port", $errno, $errstr, 6);
if (!$check)
{
echo '<font color="#FFF0000">Server is currently down!</font>';
}
else {
echo '<font color="#009900">Everything is fine</font>';
}
?>

Otherwise a great idea and something I have never thought of using, thank you for the tip.

Jonessie

Reply
Add comments to "Creating a Website / Server Monitoring Script"

Captcha