如何制作更好的httpd down checker?

时间:2013-07-01 05:55:32

标签: apache

我有apache down checker脚本(远程服务器),但我认为如果httpd有超时问题或类似的东西它不起作用。

例如,站点处于脱机状态,但服务器处于联机状态。 我应该把超时的东西或别的东西?怎么样??

<?php
function GetServerStatus($site, $port)
{
$status = array("OFFLINE", "ONLINE");
$fp = @fsockopen($site, $port, $errno, $errstr, 2);
if (!$fp) {
    return $status[0];
} else 
  { return $status[1];}
}
?>

<?php
$status =  GetServerStatus('xxx.xxx.xxx.xxx',80);
    if($status == 'OFFLINE') {
    $message = "Server is down now!!";
}
?>

1 个答案:

答案 0 :(得分:0)

我看不出这怎么可能报错。您可以考虑发送GET /请求并将其计时。

您还可以考虑在成功案例中关闭套接字。