2012-07-01 29 views
5

我买了一台服务器,我需要检查它的网络连接(速度)。如何检查我的服务器的上传和下载速度?

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

我GOOGLE了,但我无法找到任何东西...

我这样做:

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


?> 

它是正确的吗?

+0

对于下载速度,我想到:安装一个bittorrent命令行客户端并下载一个Linux发行版(不是太新,但不能太老,以便有很多种子)。通常所有这些种子都可以像服务器一样快速发送。 – Aufziehvogel

+0

对我来说看起来很好。它工作吗? – PeeHaa

回答

9

尝试:

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


?> 
+0

我做到了这一点: <?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“服务器的速度是:$ speed MB/s”; ?> 它是否正确? – HtmHell

+0

差不多,它会每秒输出字节数,而不是MB/s – lauriys

5

如果你有远程桌面,然后安装一个Web浏览器并转到speedtest.net和测试速度。

如果不是,这里是你如何测试服务器的下载速度:

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

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

0

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

$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 
+0

第一行。 mictotime。另外,100 KB = 102400 B,而不是100000. – lauriys

+0

恕我直言microtime会更好,更准确。 – lauriys

+0

我注意到张贴后几秒钟的'microtime'事情。感谢您指出。关于文件大小,在我看来并不重要,结果不会有太大的差别。 –

2

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

例子:

$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头缺失)

运行了几次,得到的平均水平,但不运行它太多,因为我不认为谷歌会喜欢它太多。

+0

谢谢,但我得到的结果并没有什么意义......当我从我的服务器上下载一个文件时,它在600kb/s,我有一个100MB/s的互联网连接...使用你的代码,我得到了这个:结果:连接:75.366973877ms上载:1,000,037字节在0.192752122879s(5066.60377186kb/s)下载:1,081字节在2.69412994385E-5s(39183.8584071kb/s) – HtmHell

+0

当您从服务器下载文件时,您的网络是瓶颈。服务器通常具有更好的互联网连接,这就是测试连接到另一台服务器的原因。 –

+0

是的,我通常以12 MB/s(从洪流和东西)下载,但从我的服务器下载,只有在600 KB/s – HtmHell

相关问题