From fc7f11db162663a9f44c206d6cbf354dd6a89490 Mon Sep 17 00:00:00 2001 From: TimZ99 Date: Sun, 24 May 2020 23:13:13 +0200 Subject: [PATCH] Reorganized and complied with PSR-12 --- src/psm/Util/Server/Updater/StatusUpdater.php | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/psm/Util/Server/Updater/StatusUpdater.php b/src/psm/Util/Server/Updater/StatusUpdater.php index a49931c2..17660bdd 100644 --- a/src/psm/Util/Server/Updater/StatusUpdater.php +++ b/src/psm/Util/Server/Updater/StatusUpdater.php @@ -175,19 +175,27 @@ class StatusUpdater */ protected function updatePing($max_runs, $run = 1) { + // Settings if ($max_runs == null || $max_runs > 1) { $max_runs = 1; } - $result = null; - // Choose right ping version, ping6 for IPV6, ping for IPV4 - $pingCommand = 'ping6'; $serverIp = $this->server['ip']; + $pingCommand = 'ping6'; + $ping_count = " -c "; + + $result = null; + + // Choose right ping version, ping6 for IPV6, ping for IPV4 if (filter_var($serverIp, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) === false) { $pingCommand = 'ping'; } + // Use -n instead of -c for Windows machines + if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { + $ping_count = " -n "; + } + // execute PING - if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') $ping_count = " -n "; else $ping_count = " -c "; $txt = exec($pingCommand . $ping_count . $max_runs . " " . $serverIp . " 2>&1", $output); // Check if output is PING and if transmitted packets is equal to received packets.