#!/bin/bash
wrst=$(mtr -r -c $1 $2 | grep -v HOST | tail -n 1 | awk '{ print ($8) }');wrst=${wrst:-"-1.0"};echo $wrst;
<?php
function getDownloadSpeed($serverAddress) {
$tempfile = '/tmp/100mb.bin-'.time();
exec('wget http://'.$serverAddress.'/100mb.bin?a='.time().' -O '.$tempfile. ' ~ 2>&1', $out);
unlink($tempfile);
foreach($out as $line) {
if (preg_match('#[\d:\s-]+\((.*?)\).*?saved#', $line, $matches)) {
return $matches[1];
}
}
}
function getPing($ip=NULL) {
$exec = exec("ping -c 3 -s 64 -t 64 ".$ip);
$array = explode("/", end(explode("=", $exec )) );
return ceil($array[1]) . 'ms';
}
function testServer($serverAddress)
{
$ping = getPing($serverAddress);
$download = getDownloadSpeed($serverAddress);
echo "Ping test: ".$ping."\n";
echo "Download speed test: ".getDownloadSpeed($serverAddress)."\n";
file_put_contents('test-vps-'.$serverAddress.'.log', date('d.m.Y H:i:s').'|'.$ping.'|'.$download."\n", FILE_APPEND);
}
testServer('server_ip');