Globally record the running time of program fragments and correctly find breakpoints that take a long time in program logic_PHP Tutorial

WBOY
Release: 2016-07-21 15:33:00
Original
802 people have browsed it

Copy code The code is as follows:

// Define global variables to record time
$_timer_id = 0;
// Function Set global variables to record the running time of each breakpoint
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++;
}
}
// Output the global running time status
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;
}
Usage:
// Start time
makeTimer( ' LINE:'.__LINE__ );
$imgstrpos = strpos($ str, '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__ );
// Record to log
error_log( traceTimer(), 3 , '/tmp/'.basename(__FILE__).'.log' );
// Or directly output
echo traceTimer();

at 2010-05-14 09 :20

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/322677.htmlTechArticleCopy code The code is as follows: // Define global variable recording time $_timer_id = 0; // Function sets global variable recording The time required to run each breakpoint function makeTimer( $notes, $onOff...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template