Elite Diviner
- Joined
- Feb 27, 2012
- Messages
- 446
- Reaction score
- 46
<?php
function check_port($port) {
$conn = @fsockopen($_SERVER['SERVER_ADDR'], $port, $errno, $errstr, 0.2);
if ($conn) {
fclose($conn);
return true;
}
}
function server_report() {
$report = array();
$svcs = array('9110'=>'World',
'9120'=>'Zone1',
'9122'=>'Zone2',
'9124'=>'Zone3',
'9010'=>'Login');
foreach ($svcs as $port=>$service) {
$report[$service] = check_port($port);
}
return $report;
}
$report = server_report();
echo
"<table>
<tr>
<td>Server</td>
<td>Status</td>
<tr>
<td>All Servers</td>
<td>"; echo $report['World']&$report['Zone1']&$report['Zone2']&$report['Zone3']&$report['Login'] ? 'Online' : 'Offline'; echo "</td>
</tr>
</table>";
?>
I tried to change it to localhost but it always returns offline. Leaving "$_SERVER['SERVER_ADDR']" should be good though right?
Also would i use php headers to cache? i haven't done much work with caching.
<?php
// Cache timeout in milliseconds
define("CACHE_TIMEOUT", 300);
function buildCache() {
// Should re-check the serverstatus here, using static stuff for now
$rgServerStatus = array(
"server1" => "offline",
"server2" => "online"
);
$pFile = fopen("cache.txt", "w");
if ($pFile !== false) {
fputs($pFile, serialize($rgServerStatus));
fclose($pFile);
}
return $rgServerStatus;
}
function loadCache() {
$pFile = fopen("cache.txt", "r");
$rgServerStatus = array();
if ($pFile !== false) {
$rgServerStatus = deserialize(fgets($pFile));
fclose($pFile);
}
return $rgServerStatus;
}
// Check if cache expired and either load cache or rebuild cache
$rgServerStatus = (filemtime("cache.txt") < (time() + CACHE_TIMEOUT) ? buildCache() : loadCache());
var_dump($rgServerStatus);
?>
Just a stupid question from me.. Can you like also use this for your VPS or website or anything else if so can you give the code to that i would like to try it out.
No i can't code PHP
Verstuurd van mijn GT-I9070 met Tapatalk
You mean modifying the script so it would monitor a website / VPS?
That sir is correct so yes.. So i can monitor all my VPS servers and Reseller server.
Verstuurd van mijn GT-I9070 met Tapatalk
Thank you for that but i just want a single code and I'm sure soneone here can provide it and if not then it's fine too.
Verstuurd van mijn GT-I9070 met Tapatalk