1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/linuxdash_ynh.git synced 2024-09-03 19:36:07 +02:00
linuxdash_ynh/sources/sh/ping.php
2014-06-02 13:38:03 +02:00

25 lines
642 B
PHP

<?php
header('Content-Type: application/json; charset=UTF-8');
// Read list of hosts to ping from csv file ping_hosts
if (file_exists("ping_hosts")) {
$hosts = file('ping_hosts', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
} else {
$hosts = array("gnu.org", "github.com", "wikipedia.org");
}
$pingCount = 2;
echo "[";
$max = count($hosts);
for ($i = 0; $i < $max; $i++) {
$result = array();
exec(
"/bin/ping -qc {$pingCount} {$hosts[$i]} |" .
" awk -F/ '/^rtt/ { print $5 }'",
$result
);
echo json_encode(array($hosts[$i], $result[0]));
echo ($i + 1 == $max) ? '' : ',';
}
echo "]";