原本 ping 功能都可正常運作,直到某天更新 PHP Server Monitor 版本後,突然失效
爬文找到這篇:Ping not working on 3.2.2 or on current development branch
修改 src/psm/Util/Server/Updater/StatusUpdater.php 裡的 updatePing function 整個替換掉後可正常運作
protected function updatePing($max_runs, $run = 1) {
if ($max_runs == NULL || $max_runs > 1) $max_runs = 1;
$txt = exec("ping -c " . $max_runs . " " . $this->server['ip']);
$re1='.*?'; # Non-greedy match on filler
$re2='[+-]?\\d*\\.\\d+(?![-+0-9\\.])'; # Uninteresting: float
$re3='.*?'; # Non-greedy match on filler
$re4='([+-]?\\d*\\.\\d+)(?![-+0-9\\.])'; # Float 1
if ($c=preg_match_all ("/".$re1.$re2.$re3.$re4."/is", $txt, $matches)) {
$result=$matches[1][0];
} else { $result = NULL; }
if (!is_null($result)) {
$status = true;
} else {
$status = false;
}
//Divide by a thousand to convert to milliseconds
$this->rtime = $result / 1000;
// check if server is available and rerun if asked.
if(!$status && $run < $max_runs) {
return $this->updatePing($max_runs, $run + 1);
}
return $status;
}