| NamePros Regular Name: Lee Location: United Kingdom Join Date: Mar 2006 | Updated Version Hi,
Here's a slightly updated version of the script I posted before, I've made it more customisable so that you can format the output however you want. PHP Code: <?php
/*
Server Status Script
Created by: Lee Findlow
Contact: leefindlow@gmail.com
Website: http://conceptsublime.com
*/
//Standard Services to Check
$services=array(
'HTTP (Port 80)' => array('localhost' => 80),
'HTTPS (Port 443)' => array('localhost' => 443),
'FTP (Port 21)' => array('localhost' => 21),
'MySQL (Port 3306)' => array('localhost' => 3306),
'SMTP (Port 25)' => array('localhost' => 25),
'POP3 (Port 110)' => array('localhost' => 110),
'Internet Connection' => array('google.com' => 80)
);
//Functions
function ServerCheck($server = 'localhost', $port = '80'){
//Connection
$fp=@fsockopen($server, $port, $errno, $errstr, 1);
//Check if connection is present
if($fp){
//Return Alive
return 1;
} else{
//Return Dead
return 0;
}
//Close Connection
fclose($fp);
}
//Function to check all services in the $services array
function CheckAll(){
//Check All Services
global $services;
foreach($services as $name => $server){
foreach($server as $host => $port){
$status[$name] = ServerCheck($host,$port);
}
}
return $status;
}
?>
This returns the services as an array, when you use the function CheckAll().
An example usage is PHP Code: <?php
include('file.php');
foreach(CheckAll() as $service => $stat){
echo $service.' - '.$stat.'<br />';
}
It returns 1/true if the service is online, and 0/false if it isn't
Thanks,
Lee  |