7

I bought a server and I need to check it's internet connection (speed).

Is there an easy way to do that?

I googled but I couldn't find anything...

I did this:

<?php

$link = 'http://speed.bezeqint.net/big.zip';
$start = time();
$size = filesize($link);
$file = file_get_contents($link);
$end = time();

$time = $end - $start;

$speed = $size / $time;

echo "Server's speed is: $speed MB/s";


?>

Is it correct?

4

4 回答 4

8

尝试:

<?php

$link = 'http://speed.bezeqint.net/big.zip';
$start = time();
$size = filesize($link);
$file = file_get_contents($link);
$end = time();

$time = $end - $start;

$size = $size / 1048576;

$speed = $size / $time;

echo "Server's speed is: $speed MB/s";


?>
于 2012-07-01T16:39:37.780 回答
6

如果您有远程桌面,请安装网络浏览器并访问speedtest.net并测试速度。

如果没有,以下是测试服务器下载速度的方法:

  • 以 root 身份登录
  • 类型wget http://cachefly.cachefly.net/100mb.test
  • 你会看到类似100%[======================================>] 104,857,600 10.7M/s- 10.7M/s 是下载速度。

如果您有超过 1 台服务器,您可以通过在 2 台服务器之间传输文件来测试上传速度。

于 2012-07-01T16:48:16.560 回答
2

Have it connect to a server you know runs fast (such as Google). Then, measure how long it takes from sending the first packet to receiving the first packet - that's your upload time. The time from receiving the first to last packets is the download time. Then divide by the amount of data transferred and there's your result.

Example:

$times = Array(microtime(true));
$f = fsockopen("google.com",80);
$times[] = microtime(true);
$data = "POST / HTTP/1.0\r\n"
       ."Host: google.com\r\n"
       ."\r\n"
       .str_repeat("a",1000000); // send one megabyte of data
$sent = strlen($data);
fputs($f,$data);
$firstpacket = true;
$return = 0;
while(!feof($f)) {
    $return += strlen(fgets($f));
    if( $firstpacket) {
        $firstpacket = false;
        $times[] = microtime(true);
    }
}
$times[] = microtime(true);
fclose($f);
echo "RESULTS:\n"
    ."Connection: ".(($times[1]-$times[0])*1000)."ms\n"
    ."Upload: ".number_format($sent)." bytes in ".(($times[2]-$times[1]))."s (".($sent/($times[2]-$times[1])/1024)."kb/s)\n"
    ."Download: ".number_format($return)." bytes in ".(($times[3]-$times[2]))."s (".($return/($times[3]-$times[2])/1024)."kb/s)\n";

(You will get an error message from Google's servers, on account of the Content-Length header missing)

Run it a few times, get an average, but don't run it too much because I don't think Google would like it too much.

于 2012-07-01T16:50:50.637 回答
0

For the download, you can create a script that will calculate the average download speed:

$start = time(true);

$fileSize = '10240'; // if the file's size is 10MB

for ($i=0; $i<10; $i++) {
    file_get_contents('the_url_of_a_pretty_big_file');
}

$end = time(true);

$speed = ($fileSize / ($end - $start)) / $i * 8;

echo $speed; // will return the speed in kbps
于 2012-07-01T16:49:37.117 回答