Skip to content

Instantly share code, notes, and snippets.

@tucq88
Created May 25, 2015 04:52
Show Gist options
  • Select an option

  • Save tucq88/1a751c8947738ccf7fc9 to your computer and use it in GitHub Desktop.

Select an option

Save tucq88/1a751c8947738ccf7fc9 to your computer and use it in GitHub Desktop.
Finding bottlenecks in your PHP code (From : http://www.codediesel.com/testing/finding-bottlenecks-in-your-php-code)
$fplog = fopen("logb.txt", "a+");
$lastlogtime = time();
function log_time($logtext)
{
global $fplog, $lastlogtime;
$nowtime = time();
$diff = $nowtime - $lastlogtime;
fwrite($fplog, sprintf("%-30s | %-30s | %-3d", $logtext, date('F Y h:i:s A', $nowtime), $diff) . PHP_EOL);
$lastlogtime = $nowtime;
}
log_time("Start");
.
.// code
.
log_time("CertainActionController");
.
..// code
.
log_time("AfterActionController");
.
..// code
.
log_time("AfterLastCodeBlock");
fwrite($fplog, PHP_EOL . "----------------------" . PHP_EOL);
fclose($fplog);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment