我想要設置一個循環或可能是一個頁面刷新,反覆ping我的服務器,並告訴我毫秒。每隔1秒鐘無限次地關閉服務器?
這是我正在使用的代碼,但不知道如何使它保持清爽,並給我現場回覆。有人可以告訴我如何讓它生活,所以它每隔1秒不斷更新,甚至每2或3秒也是如此。只需要它活着。
<?php
function pingDomain($domain){
$starttime = microtime(true);
// supress error messages with @
$file = @fsockopen($domain, 80, $errno, $errstr, 10);
$stoptime = microtime(true);
$status = 0;
if (!$file){
$status = -1; // Site is down
}
else{
fclose($file);
$status = ($stoptime - $starttime) * 1000;
$status = floor($status);
}
return $status;
}
?>
Server Latency: <?php echo pingDomain('192.168.1.20'); ?> ms<br>
編輯與保羅的代碼仍然沒有運氣:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html;" />
<meta http-equiv="refresh" content="1; url='yourPage.php'" />
</head>
<body>
<?php
function pingDomain($domain){
$starttime = microtime(true);
// supress error messages with @
$file = @fsockopen($domain, 80, $errno, $errstr, 10);
$stoptime = microtime(true);
$status = 0;
if (!$file){
$status = -1; // Site is down
}
else{
fclose($file);
$status = ($stoptime - $starttime) * 1000;
$status = floor($status);
}
return $status;
}
?>
Server Latency: <?php echo pingDomain('192.168.1.20'); ?> ms<br>
</body>
</html>
這將是一個矯枉過正的+爲什麼重新發明輪子?有這麼多的開源服務器監控解決方案已經上市。 – 2014-12-04 07:44:32
如何過度監控我的服務器,以便通過觀看此腳本,我可以在幾秒鐘內知道它的下載情況?我可以從手機或其他任何地方訪問腳本。我不需要一些高科技腳本就像這樣一個非常簡單的東西。如果你在某個方向上知道一點我。 – FrostByte 2014-12-04 07:54:29
示例程序對我來說工作正常。你有什麼問題呢? – Volvox 2014-12-04 08:14:50