<?php
//Page Variables
$online='<td style="background-color:#00FF00; padding:5px;">Operational</td>';
$offline='<td style="background-color:#FF0000; padding:5px;">Failed</td>';
//Functions
function servercheck($server,$port){
//Check that the port value is not empty
if(empty($port)){
$port=80;
}
//Check that the server value is not empty
if(empty($server)){
$server='domain.com';
}
//Connection
[email protected]($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);
}
//Ports and Services to check
$services=array(
'Website Access' => array('domain.com' => 80),
'Another Service' => array('domain.com' => 443),
'Another Service' => array('domain.com' => 21),
);
?>
<div class="infobox">
<?php
//Check All Services
foreach($services as $name => $server){
?>
<tr>
<td><?php echo $name; ?></td>
<?php
foreach($server as $host => $port){
if(servercheck($host,$port)){ echo $online; }else{ echo $offline; }
}
?>
</tr>
<?php
}
?>
</div>
<div class="overallmesssage">
<h3>
<!--Need this bit to show green and a message if all servers online if not show orange for not all of them and red for none of them-->
</div>
我想添加一個總體消息,這些消息根據在線服務器而變化。類似於https://demo.cachethq.io/,其中有一個綠色的整體部分告訴訪問者一切正常並且正在運行,但如果其中一臺服務器停機,它將變爲橙色,如果所有服務器都停機,它將變爲紅色。PHP - 如果所有陣列都處於活動狀態,無效狀態或不可用,請顯示消息
我認爲你的意思是'如果(servercheck($ host,$ port)== 0)' – hassan
哦對不起是的... :)我改變了這一點。 – Stony
歡迎大家使用'setInterval'而不是cron? – hassan