首页 > Web开发 > 详细

PHP - 计算执行程序耗时

时间:2015-11-12 11:26:28      阅读:332      评论:0      收藏:0      [点我收藏+]

效果:

技术分享

 

首先在includes文件夹下编写,global.func.php函数库:

<?php

    /*
    *     Version:1.0
    *    CreateTime:2015年11月11日
    *    Author:HF_Ultrastrong
    */
    
    /**
     *_runtirm():使用来生成程序耗时
     *@access public:公开访问
     *@return float :返回值为浮点型
     *
     * */
    function _runtime(){
        $mtime = microtime();
        $time = explode( , $mtime);
        return $time[1]+$time[0];
    }

?>

 

然后在common.inc.php公共文件中引用:

<?php

    /*
    *     Version:1.0
    *    CreateTime:2015年11月11日
    *    Author:HF_Ultrastrong
    */
    
    //判断页面是否为非法调用
    if (!defined(IN_TG)) {
        //不是正常调用,跳转到404页面
        header(Location:.../error/404.html);
    }
    
    //定义相对于项目的绝对路径,用以加快调用页面的速度。
    define(ROOT_PATH, substr(dirname(__FILE__),0,-8));
    
    //判断PHP版本是否太低
    if (PHP_VERSION < 4.1.0) {
        echo Version is to Low!;
        exit;
    }
    
    //引入函数库global.func.php
    require ROOT_PATH./includes/global.func.php;
?>

 

然后将common公共文件在index.php主文件中引用:

技术分享

 

之后在header.inc.php中生成开始时间:

  • 将生成时间存入常量

 技术分享

 

之后再footer.inc.php文件写下,结束时间,然后相减,得到耗时。

<?php

    /*
    *     Version:1.0
    *    CreateTime:2015年11月11日
    *    Author:HF_Ultrastrong
    */
    //判断页面是否为非法调用
    if (!defined(IN_TG)) {
        //不是正常调用,跳转到404页面
        header(Location:.../error/404.html);
    }
?>
<div id="footer">
    <p>本程序执行耗时:<?php echo [ .round(_runtime()- START_TIME,5).s ]; ?></p>
    <p>版权所有,违者必究 --- HF_Ultrastrong@copyright</p>
</div>

 

PHP - 计算执行程序耗时

原文:http://www.cnblogs.com/KTblog/p/4958098.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!