分享

php获取程序执行时间的代码

 乡间小路有风景 2013-07-21

例1,
在head.htm中加入,即在默认模版中添加:“$stime=microtime(true); //获取程序开始执行的时间”。
代码如下所示:
 

复制代码代码示例:

<!--<?php
$stime=microtime(true); //程序开始执行的时间
$GuideFid[$fid]=str_replace()("<a href='$webdb[www_url]' class='guide_menu'>>首页</a>","",$GuideFid[$fid]);
$fupId=intval($fupId);
$topMenu[$fupId]='ck';
print <<<EOT
-->

//这里是网页
//再在foot.htm修改,如下所示:
<!--
EOT;
$etime=microtime(true);//获取程序执行结束的时间
$total=$etime-$stime; //计算差值
echo "<br />[页面执行时间:{$total} ]秒";
?>

例2,
 

复制代码代码示例:
<?
$pagestartime=microtime();
?>
<!--网页内容 start-->
网页内容
...
...
<!--网页内容 end-->
<?
$pageendtime = microtime();
$starttime = explode()(" ",$pagestartime);
$endtime = explode(" ",$pageendtime);
$totaltime = $endtime[0]-$starttime[0]+$endtime[1]-$starttime[1];
$timecost = sprintf()("%s",$totaltime);
echo "页面运行时间: $timecost 秒";
//by www.
?>

例3,
计算页面执行时间
在php网页的开头加入:
 

复制代码代码示例:
<?
//计算页面执行时间
$time_start = getmicrotime();
function getmicrotime()
{
list($usec, $sec) = explode(" ",microtime());
return ((float)$usec + (float)$sec);
}
?>
 

然后,在页面结尾加入:
 

复制代码代码示例:
<?
$time_end = getmicrotime();
printf ("[页面执行时间: %.2f毫秒]\n\n",($time_end - $time_start)*1000);
//统计出当前页的执行时间
?>

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多