|
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 |
ZeroFill Smarty Rookie
Joined: 31 Aug 2003 Posts: 28
|
Posted: Sun Aug 31, 2003 11:19 pm Post subject: setting "Page loaded in x.xxx seconds" with smarty |
|
|
hi, i'm sorry if this has already been discussed. my search didn't come up with anything specific to my question.
before i switched to smarty, i made the normal microtimes in both the header and footer.inc.php files then displayed the difference. is there a way to do this with smarty?
i know can do microtime at the beginning and end of every script but is there a better way of doing this, which also includes smarty compile time?
[edit]
strange. i can't change the topic. i forgot the question mark
[edit2]
n/m. i guess i can always make my own template function |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Mon Sep 01, 2003 12:02 am Post subject: |
|
|
Hi Zerofill.
Reporting time from Smarty directly will ignore other things that take time--for example, the creation of your business objects, the smarty classes, application logic, db access...the list goes on.
If you do want to time blocks within Smarty, your idea of a template function is valid, though I suggest a block function. I wrote something like that which you may find of use: block function: timeblock. |
|
Back to top |
|
ZeroFill Smarty Rookie
Joined: 31 Aug 2003 Posts: 28
|
Posted: Mon Sep 01, 2003 12:03 am Post subject: |
|
|
i made a quick hacked Template Function for anyone that might want or improve upon it
[php:1:3516362ac1]
<?php
/*
* Smarty plugin
* ----------------------------------------
* File: function.page_load.php
* Type: function
* Name: page_load
* Purpose: outputs the difference between ending microtime and beginning microtime
* Note: MUST $smarty->assign('start_load_time', $start_load_time) for it to work.
* ------------------------------------------
*/
function smarty_function_page_load($params, &$smarty)
{
$start_load_time = $smarty->get_template_vars('start_load_time');
if (empty($start_load_time))
{
$smarty->trigger_error("assign: missing 'start_load_time'");
return;
}
return $smarty->_get_microtime() - $start_load_time;
}
?> [/php:1:3516362ac1]
example
Code: |
// index.php
$mtime = microtime();
$mtime = explode(" ", $mtime);
$start_load_time = (double)($mtime[1]) + (double)($mtime[0]);
..some code..
$smarty->assign('start_load_time',$start_load_time);
$smarty->display('index.tpl');
// footer.tpl
Page loaded in <{page_load|truncate:8:""}> seconds
|
[edit]
thanks for the link. i'm sure it'll be more accurate than mine
[edit]
yep. the results are surprisingly different
mine: Page loaded in 0.102422 seconds (and jumps between .09 and .5 for some reason)
yours: [page_load] Elapsed Time 0.048163s |
|
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
|