不需要扩展,只需使用这两个函数进行简单的分析。
// Call this at each point of interest, passing a de ive string
function prof_flag($str)
{
global $prof_timing, $prof_names;
$prof_timing[] = microtime(true);
$prof_names[] = $str;
}
// Call this when you\'re done and want to see the results
function prof_print()
{
global $prof_timing, $prof_names;
$size = count($prof_timing);
for($i=0;$i<$size - 1; $i++)
{
echo \"<b>{$prof_names[$i]}</b><br>\";
echo sprintf(\" %f<br>\", $prof_timing[$i+1]-$prof_timing[$i]);
}
echo \"<b>{$prof_names[$size-1]}</b><br>\";
}
下面是一个示例,调用prof_flag(),每个检查点都有一个描述,最后是prof_print():
prof_flag(\"Start\");
include \'../lib/data .php\';
include \'../lib/helper_func.php\';
prof_flag(\"Connect to DB\");
connect_to_db();
prof_flag(\"Perform query\");
// Get all the data
$select_query = \"SELECT * FROM data_table\";
$result = mysql_query($select_query);
prof_flag(\"Retrieve data\");
$rows = array();
$found_data=false;
while($r = mysql_fetch_assoc($result))
{
$found_data=true;
$rows[] = $r;
}
prof_flag(\"Close DB\");
mysql_close(); //close data connection
prof_flag(\"Done\");
prof_print();
输出看起来像这样:
开始
0.004303
连接到DB
0.003518
执行查询
0.000308
检索数据
0.000009
关闭DB
0.000049
完成
继续阅读与本文标签相同的文章
-
富士康“败走”印度!只要加班就辞职,郭台铭还能“霸气”起来?
2026-05-15栏目: 教程
-
互联网的下半场,在大小城市里飞驰的电瓶车上
2026-05-15栏目: 教程
-
Robotframework-RED-指定测试报告存放的路径
2026-05-15栏目: 教程
-
株洲首个数据中心站投运
2026-05-15栏目: 教程
-
微软Edge新标签页迎来新布局:新闻区可替换为工作相关内容
2026-05-15栏目: 教程
