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

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
Thank you for voting.
Rate this Materials:
Bad 
1 2 3 4 5 Excellent
print this page subscribe to newsletter subscribe to rss

Web programming � everything from the basics of visual design and architecture to the specifics of applications, graphics, and scripting. More Web Programming: Most Popular Materials | Fresh Materials | More PHP Tutorials at LearnPHP.org

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

Only registered users can write comment

Reader's comments
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.

Code:
$site = 'yourwebsite.com';
$port = '80';
$check = fsockopen("$site", "$port", $errno, $errstr, 6);
if (!$check)
{
echo 'Server is currently down!';
}
else {
echo 'Everything is fine';
}
?>


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

Jonessie