色尼玛亚洲综合影院,亚洲3atv精品一区二区三区,麻豆freexxxx性91精品,欧美在线91

全局記錄程序片段的運行時間 正確找到程序邏輯耗時多的斷點

復制代碼 代碼如下:
// 定義全局變量 記錄時間
$_timer_id = 0;
// 函數設置全局變量 記錄各個斷點的運行所需時間
function makeTimer( $notes, $onOff=FALSE )
{
if( $onOff )
{
global $_timer_id;
$GLOBALS['timer'][$_timer_id][0] = microtime(TRUE);
$GLOBALS['timer'][$_timer_id][1] = $notes;
$_timer_id++;
}
}
// 把全局運行時間情況輸出
function traceTimer()
{
$timer_str = '';
$G_timer = count($GLOBALS['timer'])-1;
if( $G_timer>0 )
{
for( $i=0;$i<$G_timer;$i++ )
{
$dif_time = number_format( ($GLOBALS['timer'][$i+1][0] - $GLOBALS['timer'][$i][0]), 3 );
$timer_str .= 'dif: '.$dif_time.' '.$GLOBALS['timer'][$i][1]."/n";
}
$dif_time = number_format( (microtime(TRUE) - $GLOBALS['timer'][$G_timer][0]), 3 );
$timer_str .= 'dif: '.$dif_time.' '.$GLOBALS['timer'][$G_timer][1]."/n";
}
return $timer_str;
}
使用方法:
// 開始時間
makeTimer( ' LINE:'.__LINE__ );
$imgstrpos = strpos($str, '<img'.$imgstr);
makeTimer( ' LINE:'.__LINE__ );
$str_p = substr($str_noimg, 0, $imgstrpos);
makeTimer( ' LINE:'.__LINE__ );
$str_n = substr($str_noimg, $imgstrpos, strlen($str_noimg));
makeTimer( ' LINE:'.__LINE__ );
$pst_exc_imgs = $str_p.'<img '.$imgstr.'>'.$str_n." ";
makeTimer( ' LINE:'.__LINE__ );
// 記錄到日志中
error_log( traceTimer(), 3, '/tmp/'.basename(__FILE__).'.log' );
// 或者直接輸出
echo traceTimer();

at 2010-05-14 09:20

php技術全局記錄程序片段的運行時間 正確找到程序邏輯耗時多的斷點,轉載需保留來源!

鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。

主站蜘蛛池模板: 当涂县| 泸定县| 广河县| 日喀则市| 筠连县| 曲阳县| 嘉禾县| 枣阳市| 平阴县| 贺州市| 桂东县| 商丘市| 铜陵市| 鄱阳县| 澳门| 日喀则市| 高台县| 油尖旺区| 梧州市| 庆阳市| 镇坪县| 临邑县| 漳平市| 五华县| 樟树市| 兴化市| 无棣县| 个旧市| 南涧| 酉阳| 古丈县| 张家口市| 察哈| 莆田市| 禄丰县| 财经| 门头沟区| 潞城市| 凤城市| 绥中县| 奇台县|