獲取php頁面執(zhí)行時間,數(shù)據(jù)庫讀寫次數(shù),函數(shù)調(diào)用次數(shù)等(THINKphp)_PHP教程
推薦:php變量作用域的深入解析本篇文章是對php變量作用域進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下
THINKphp里面有調(diào)試運行狀態(tài)的效果:Process:0.2463s (Load:0.0003s Init:0.0010s Exec:0.1095s Template:0.1355s )|DB:13 queries 0 writes| Cache:2 gets,0 writes|UseMem:415 kb|LoadFile:20|CallFun:63,1370
代表的含義:
運行信息: 整體執(zhí)行時間0.2463s ( 加載:0.0003s 初始化:0.0010s 執(zhí)行:0.1095s 模板:0.1355s ) | 數(shù)據(jù)庫 :13次讀操作 0次寫操作 | 緩存:2次讀取,0次寫入 | 使用內(nèi)存:415 kb | 加載文件:20 | 函數(shù)調(diào)用:63(自定義),1370(內(nèi)置)
下面來分析一下這些數(shù)據(jù)是怎么獲取到的?
PHP獲取頁面執(zhí)行時間:
復(fù)制代碼 代碼如下:www.wf0088.com
/**
* 得到當(dāng)前時間
*/
function getMicrotime() {
list ($usec, $sec) = explode(" ", microtime());
return ((float) $usec + (float) $sec);
}
使用:上面的方法可以獲取當(dāng)前時間,計算頁面執(zhí)行時間可以在程序開頭和結(jié)尾出分別執(zhí)行該方法,最后時間差就是頁面執(zhí)行的時間,原理很簡單。
獲取數(shù)據(jù)庫讀寫次數(shù)
在數(shù)據(jù)庫插入和讀取的時候設(shè)置一個全局變量,每次執(zhí)行成功一次$i++一次,
![](/uploads/allimg/c130604/13F34C25260-11Z9.gif)
同理緩存也是這樣計算出來的
內(nèi)存的開銷
memory_get_usage可以獲取當(dāng)前內(nèi)存的消耗量,可以在程序開始和結(jié)尾分別調(diào)用,差值就是內(nèi)存的開銷
加載文件的數(shù)量
get_included_files:Gets the names of all files that have been included using include, include_once, require or require_once.
也就是可以獲取到所有的include,require的文件數(shù),返回引入文件的數(shù)組:
官網(wǎng)例子":
復(fù)制代碼 代碼如下:www.wf0088.com
<?php
// This file is abc.php
include 'test1.php';
include_once 'test2.php';
require 'test3.php';
require_once 'test4.php';
$included_files = get_included_files();
foreach ($included_files as $filename) {
echo "$filenamen";
}
?>
返回的結(jié)果是:
abc.php
test1.php
test2.php
test3.php
test4.php
函數(shù)調(diào)用方法
第一個看這個,感覺是在每個方法里面調(diào)用時自動+1.但是感覺不大可能,貌似這個每個方法里寫不靠譜,這群里討論半天,最后發(fā)現(xiàn)php的一個函數(shù):
get_defined_functions返回引入PHP文件的所有方法的array格式,包括自定義的,內(nèi)置的。
引入官網(wǎng)的一個例子:
復(fù)制代碼 代碼如下:www.wf0088.com
<?php
function myrow($id, $data)
{
return "<tr><th>$id</th><td>$data</td></tr>n";
}
$arr = get_defined_functions();
print_r($arr);
?>
結(jié)果是:
復(fù)制代碼 代碼如下:www.wf0088.com
Array
(
[internal] => Array
(
[0] => zend_version
[1] => func_num_args
[2] => func_get_arg
[3] => func_get_args
[4] => strlen
[5] => strcmp
[6] => strncmp
...
[750] => bcscale
[751] => bccomp
)
[user] => Array
(
[0] => myrow
)
)
user為自定義方法,internal為內(nèi)置方法數(shù)組。
引申:
get_defined_constants 獲取定義所有常量的數(shù)組
get_defined_functions 獲取定義所有函數(shù)的數(shù)組
get_defined_vars 獲取定義所有變量的數(shù)組
get_declared_classes 返回已經(jīng)定義的類的數(shù)組
分享:CURL的學(xué)習(xí)和應(yīng)用(附多線程實現(xiàn))這篇文章主要介紹了CURL的安裝與多線程實現(xiàn)方法,需要的朋友可以參考下
相關(guān)PHP教程:
- 相關(guān)鏈接:
復(fù)制本頁鏈接| 搜索獲取php頁面執(zhí)行時間,數(shù)據(jù)庫讀寫次數(shù),函數(shù)調(diào)用次數(shù)等(THINKphp)
- 教程說明:
PHP教程-獲取php頁面執(zhí)行時間,數(shù)據(jù)庫讀寫次數(shù),函數(shù)調(diào)用次數(shù)等(THINKphp)
。