php实现的Timer页面运行时间监测类__4.docx

上传人:啊飒飒 文档编号:11646282 上传时间:2021-08-27 格式:DOCX 页数:5 大小:12.30KB
返回 下载 相关 举报
php实现的Timer页面运行时间监测类__4.docx_第1页
第1页 / 共5页
php实现的Timer页面运行时间监测类__4.docx_第2页
第2页 / 共5页
php实现的Timer页面运行时间监测类__4.docx_第3页
第3页 / 共5页
php实现的Timer页面运行时间监测类__4.docx_第4页
第4页 / 共5页
php实现的Timer页面运行时间监测类__4.docx_第5页
第5页 / 共5页
亲,该文档总共5页,全部预览完了,如果喜欢就下载吧!
资源描述

《php实现的Timer页面运行时间监测类__4.docx》由会员分享,可在线阅读,更多相关《php实现的Timer页面运行时间监测类__4.docx(5页珍藏版)》请在三一文库上搜索。

1、php实现的Timer页面运行时间监测类_ 本文实例讲解并描述了php实现的Timer页面运行时间监测类及其用法,是一款特别有用的PHP类文件。分享给大家供大家参考。具体分析如下: 该php Timer页面运行时间监测类,可按不同key监测不同的运行时间。 Timer.class.php类文件如下: ?php /* Timer class, 计算页面运行时间,可按不同key计算不同的运行时间 * Date: 2021-02-28 * Author: fdipzone * Ver: 1.0 * * Func: * public start 记录开头时间 * public end 记录结束时间 *

2、 public getTime 计算运行时间 * pulbic printTime 输出运行时间 * private getKey 猎取key * private getMicrotime 猎取microtime */ class Timer / class start private $_start = array(); private $_end = array(); private $_default_key = Timer; private $_prefix = Timer_; /* 记录开头时间 * param String $key 标记 */ public function st

3、art($key=) $flag = $this-getKey($key); $this-_start$flag = $this-getMicrotime(); /* 记录结束时间 * param String $key 标记 */ public function end($key=) $flag = $this-getKey($key); $this-_end$flag = $this-getMicrotime(); /* 计算运行时间 * param String $key 标记 * return float */ public function getTime($key=) $flag

4、= $this-getKey($key); if(isset($this-_end$flag) isset($this-_start$flag) return (float)($this-_end$flag - $this-_start$flag); else return 0; /* 输出页面运行时间 * param String $key 标记 * return String */ public function printTime($key=) printf(%srun time %f msrn, $key=? $key : $key. , $this-getTime($key)*100

5、0); /* 猎取key * param String $key 标记 * return String */ private function getKey($key=) if($key=) return $this-_default_key; else return $this-_prefix.$key; /* 猎取microtime */ private function getMicrotime() list($usec, $sec) = explode( , microtime(); return (float)$usec + (float)$sec; / class end ? de

6、mo示例代码如下: ?php require Timer.class.php; $timer = new Timer(); $timer-start(); $timer-start(program1); usleep(mt_rand(100000,500000); $timer-end(program1); $timer-printTime(program1); $timer-start(program2); usleep(mt_rand(100000,500000); $timer-end(program2); $timer-printTime(program2); $timer-end(); $timer-printTime(); ? demo运行输出: program1 run time 163.285971 ms program2 run time 100.347042 ms run time 264.035940 ms 更多信息请查看IT技术专栏 .

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 科普知识


经营许可证编号:宁ICP备18001539号-1