Skip to content

Instantly share code, notes, and snippets.

@niko
Last active November 24, 2016 13:46
Show Gist options
  • Save niko/b1e4c7c65cbdf4104458ec8ca45bd074 to your computer and use it in GitHub Desktop.
Save niko/b1e4c7c65cbdf4104458ec8ca45bd074 to your computer and use it in GitHub Desktop.
<?php
header('Content-Type: text/plain');
function ping($addr){
$starttime = microtime(true);
$file = fsockopen ($addr, 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;
}
$addr = '31.7.184.137';
echo "lautfm_stream_ping{server=\"" . $_SERVER['SERVER_NAME'] . "\", addr=\"" . $addr . "\"} " . ping($addr) . "\n";
$addr = '81.95.11.211';
echo "lautfm_stream_ping{server=\"" . $_SERVER['SERVER_NAME'] . "\", addr=\"" . $addr . "\"} " . ping($addr) . "\n";
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment