|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
Dor Smarty n00b
Joined: 14 May 2005 Posts: 1 Location: Moscow, Russia
|
Posted: Sat May 14, 2005 3:25 pm Post subject: |
|
|
May be I misunderstood smthng but I have one question: what for all this complicated stuff? Debugging console ALREADY have compiling time.
And I already have timestats for SQLs and for my PHP code. All that I really need is SMARTY compile times. But I can't get 'em whithout calling SMARTY console. May be there is some way to get compile times WITHOUT showing a console?
I guess SMARTY should have some inner variable with timestats that can be accessed within template(debug.tpl ). Possibly it is empty when not debugging, but I belive there are should be some workaround
---
sorry, if my "english" is a little strange - I have really little practice in it _________________ Press RESET twice to login. |
|
Back to top |
|
JurgenD Smarty Rookie
Joined: 20 Jul 2005 Posts: 12 Location: Belgium
|
Posted: Wed Jul 20, 2005 5:32 pm Post subject: |
|
|
I have another approuch to generate it FAST. Because, If You calculate the parsing time of a generated page, Your function does need to be short and fast, to have sharp results.
It works wirht a STATIC variable, and You need to call it twice. On top and on bottom of the template. You may not cache this function.
Code: |
// smarty function: stopwatch
// Descr : This function calculates parse time of Your templates
// in microtime
// Author: DEBO Jurgen E. G.
// Usage : Call this twice on top of Your template, and before </body>
// Ex:
// {stopwatch}
// <html>
// ...
// <p>This page was generated in {stopwatch} seconds</p>
// </body>
// Call : $smarty->register_function('stopwatch', 'stopwatch', false);
// note : Function may NOT be cached
//
function stopwatch($params, &$smarty){
static $mt_previous = 0;
//list($usec, $sec) = explode(" ",microtime());
//$mt_current = (float)$usec + (float)$sec;
$mt_current = (float) array_sum(explode(' ', microtime()));
if (!$mt_previous) {
$mt_previous = $mt_current;
return "";
} else {
$mt_diff = ($mt_current - $mt_previous);
$mt_previous = $mt_current;
return sprintf('%.16f',$mt_diff);
}
}
|
NOTE: If You do NOT want to bother Your visitors with the parsing info
put it in comment on Your pages in this way:
Code: |
<!-- This page was generated in {stopwatch} seconds -->
|
|
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|