PHP

效果:

首先在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>
原文地址:https://www.cnblogs.com/KTblog/p/4958098.html