加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

PHP 一个页面执行时间类代码

发布时间:2020-12-13 05:40:23 所属栏目:PHP教程 来源:网络整理
导读:核心代码 starttime=this->getmicrotime(); } function display()//显示页面执行的时间 { this->stoptime=this->getmicrotime(); this->spendtime=this->stoptime-this->starttime; return round(this->spendtime,10); } } /*调用方法 timer=new Timer(); ti

核心代码

starttime=this->getmicrotime(); } function display()//显示页面执行的时间 { this->stoptime=this->getmicrotime(); this->spendtime=this->stoptime-this->starttime; return round(this->spendtime,10); } } /*调用方法 timer=new Timer(); timer->start(); /*在此处放入你要执行的脚本或代码 for(i=0;i<100000;i++) { echo i; echo "
"; } */ //echo "

执行该代码花费时间".timer->display()."秒"; ?>

PHP检测每一段代码执行时间

/**

  • @start time
    */
    function proStartTime() {
    global $startTime;
    $mtime1 = explode(" ",microtime());
    $startTime = $mtime1[1] + $mtime1[0];
    }

/**

  • @End time
    */
    function proEndTime() {
    global $startTime,$set;
    $mtime2 = explode(" ",microtime());
    $endtime = $mtime2[1] + $mtime2[0];
    $totaltime = ($endtime - $startTime);
    $totaltime = number_format($totaltime,7);
    echo "
    process time: ".$totaltime;
    }

// 程序调用开始记时
proStartTime();

sleep(1); // sleep() 延时代码执行若干秒
proEndTime(); // 程序在每一段所消耗的执行时间
sleep(2);
proEndTime();
sleep(3);
proEndTime();

/***** 华丽的分割线 **/

// 实例2

$t1 = microtime(true);
sleep(3);
$t2 = microtime(true);
echo '程序耗时'.round($t2-$t1,3).'秒';

?>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读