website promotion banner
eturnkeys
Your Ad Here
Web Programming  Home Web Programming PHP Creating a Website / Server Monitoring Script
rss

Creating a Website / Server Monitoring Script

Author: James More by this author


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: www.sigtutorials.com

Rate this Material: Bad 1 2 3 4 5 Excellent
print this page tell a friend subscribe to newsletter subscribe to rss

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

comments  Jonessie July 05, 2007 says:
Creating a Website / Server Monitoring Script
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 ""; this will produce an error. Whilst using ''; will be fine. I tinckered with your code a little, because it was a little cluttered.
:
<?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