Created
September 13, 2021 13:59
-
-
Save kobus1998/a85a907f78712d5241d52de6c3f12ec5 to your computer and use it in GitHub Desktop.
average ping from server
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/local/bin/php -q | |
<?php | |
// php ping.php google.com | |
$sHost = escapeshellarg($argv[1] ?? 'localhost'); | |
$sCmd = "ping {$sHost}"; | |
echo $sCmd . "\n"; | |
$proc = popen($sCmd, 'r'); | |
$aNums = []; | |
while (!feof($proc)) { | |
$sLine = fread($proc, 4096); | |
$aParams = array_filter(explode(" ", $sLine), function ($sParams) { | |
return strpos($sParams, '=') !== false || !strpos($sParams, 'time'); | |
}); | |
$aNums[] = str_replace('time=', '', reset($aParams)); | |
echo round(array_sum($aNums) / count($aNums), 8) . " Ping\n"; | |
flush(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment