上一篇: PHP Curl 多线程实现
PHP 计算页面执行时间
[ 2010/08/11 12:29 | by selboo ]
[root@74-82-173-217 ~]# cat runtime.php
<?php
class runtime
{
var $StartTime = 0;
var $StopTime = 0;
function get_microtime()
{
list($usec, $sec) = explode(' ', microtime());
return ((float)$usec + (float)$sec);
}
function start()
{
$this->StartTime = $this->get_microtime();
}
function stop()
{
$this->StopTime = $this->get_microtime();
}
function spent()
{
return round(($this->StopTime - $this->StartTime) * 1000, 1);
}
}
?>
<?php
class runtime
{
var $StartTime = 0;
var $StopTime = 0;
function get_microtime()
{
list($usec, $sec) = explode(' ', microtime());
return ((float)$usec + (float)$sec);
}
function start()
{
$this->StartTime = $this->get_microtime();
}
function stop()
{
$this->StopTime = $this->get_microtime();
}
function spent()
{
return round(($this->StopTime - $this->StartTime) * 1000, 1);
}
}
?>
在 php 文件头加上开始代码
include ("runtime.php");
$runtime= new runtime;
$runtime->start();
$runtime= new runtime;
$runtime->start();
在 php 文件尾部加上结束代码
$runtime->stop();
echo "页面执行时间: ".$runtime->spent()." 毫秒";
echo "页面执行时间: ".$runtime->spent()." 毫秒";
最后编辑: selboo 编辑于2010/08/11 13:28