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


Like us to: