Home >php教程 >PHP源码 >PHP测试网速

PHP测试网速

PHP中文网
PHP中文网Original
2016-05-25 17:13:552001browse

一段测试你网络速度的PHP

<?php

//$file = fopen(&#39;abc.txt&#39;,&#39;w&#39;);
//for($i=0;$i<170400;$i++) fwrite($file,&#39;helloworld&#39;);
//fclose($file);

$data = file_get_contents(&#39;abc.txt&#39;);
$fsize = filesize("abc.txt")/1024;

$start = gettime();

echo $data;

$end = gettime();

$cs = ($end[&#39;0&#39;]+$end[&#39;1&#39;]) - ($start[&#39;0&#39;]+$start[&#39;1&#39;]);

$speed = round(($fsize / $cs),2);

echo "
network: ".$speed." KB/sec.";


function gettime()
{
return explode(" ",microtime()); 
}

                   


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:PHP生成友好URLNext article:安全的 URL 跳转