【问题标题】:How to check my server's upload and download speed? [closed]如何检查我的服务器的上传和下载速度? [关闭]
【发布时间】:2012-07-01 16:37:16
【问题描述】:

我买了一台服务器,我需要检查它的互联网连接(速度)。

有没有简单的方法可以做到这一点?

我用谷歌搜索,但我找不到任何东西......

我这样做了:

<?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";


?>

对吗?

【问题讨论】:

  • 为了下载速度,我想到了:安装一个bittorrent命令行客户端并下载一个linux发行版(不要太新,但不要太旧,这样有很多种子)。通常,所有这些种子都可以尽可能快地发送您的服务器。
  • 对我来说看起来不错。有用吗?

标签: php performance download monitor


【解决方案1】:

试试:

<?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";


?>

【讨论】:

  • 我这样做了:speed.bezeqint.net/big.zip'; $开始=时间(); $size = 文件大小($link); $file = file_get_contents($link); $结束=时间(); $time = $end - $start; $速度= $大小/$时间; echo "服务器速度为:$speed MB/s"; ?> 对吗?
  • 几乎是每秒输出字节数,而不是MB/s
【解决方案2】:

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

如果没有,您可以通过以下方式测试服务器的下载速度:

  • 以 root 身份登录
  • 输入wget http://cachefly.cachefly.net/100mb.test
  • 您会看到类似100%[======================================&gt;] 104,857,600 10.7M/s 的内容 - 10.7M/s 是下载速度。

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

【讨论】:

  • 或者使用speedtest-cli,不需要在服务器上运行GUI。
【解决方案3】:

让它连接到您知道运行速度很快的服务器(例如 Google)。然后,测量从发送第一个数据包到接收到第一个数据包需要多长时间——这就是你的上传时间。从接收到第一个数据包到最后一个数据包的时间是下载时间。然后除以传输的数据量,就是你的结果。

例子:

$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";

(由于缺少 Content-Length 标头,您会从 Google 的服务器收到一条错误消息)

运行几次,取平均值,但不要运行太多,因为我认为 Google 不会太喜欢它。

【讨论】:

  • 谢谢,但我得到的结果并没有什么意义......当我从服务器下载文件时,它的速度为 600kb/s,而我的互联网连接速度为 100MB/s。 . 使用您的代码我得到了: 结果:连接:75.366973877ms 上传:0.192752122879s (5066.60377186kb/s) 中的 1,000,037 个字节 下载:2.69412994385E-5s (39183.8584071kb/s) 中的 1,081 个字节
  • 当您从服务器下载文件时,您的网络是瓶颈。服务器通常具有更好的互联网连接,这就是测试连接到另一台服务器的原因。
  • 是的,我通常以 12 MB/s 的速度下载(来自 torrent 和其他东西),但从我的服务器下载,只有大约 600 KB/s
【解决方案4】:

对于下载,您可以创建一个脚本来计算平均下载速度:

$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

【讨论】:

  • 第一行。微时。此外,100 KB = 102400 B,而不是 100000。
  • 恕我直言,微时间会更好,更准确。
  • 我在发帖几秒钟后就注意到了 microtime 的事情。感谢您指出。关于文件大小,我认为这并不重要,不会对结果产生太大影响。
  • 如果文件为 100 KB,时间/微时间会有所不同:P
  • 100KB 只是一个例子,这就是我在file_get_contents() 中提到“the_url_of_a_pretty_big_file”的原因。
猜你喜欢
  • 2014-02-17
  • 2015-01-27
  • 2020-09-02
  • 2019-05-30
  • 1970-01-01
  • 2011-08-25
  • 2010-10-15
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多