有它连接到你知道的服务器运行速度快(如谷歌)。然后,测量从发送第一个数据包到接收第一个数据包需要多长时间 - 这是您的上传时间。从接收第一个到最后一个数据包的时间是下载时间。然后除以传输的数据量并得到结果。
例子:
$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
头缺失)
运行了几次,得到的平均水平,但不运行它太多,因为我不认为谷歌会喜欢它太多。
对于下载速度,我想到:安装一个bittorrent命令行客户端并下载一个Linux发行版(不是太新,但不能太老,以便有很多种子)。通常所有这些种子都可以像服务器一样快速发送。 – Aufziehvogel
对我来说看起来很好。它工作吗? – PeeHaa