Can I Display Page Parse Time in Smarty Template?

Discussion in 'PHP' started by assembler, Jul 17, 2006.

  1. #1
    I'm trying to determine the page parse time of a 3rd-party application. I only have access to the Smarty Templates. Can I use inline PHP to display the actual parse time, or is processing time done outside of the smarty template?

    Using some code from one of Chemo's osCommerce contributions:

    The first line of my top smarty template is:
    
    {php}define('PAGE_PARSE_START_TIME', microtime());{/php}
    
    PHP:
    The last line of my bottom smarty template is:
    
    {php}
    $time_start = explode(' ', PAGE_PARSE_START_TIME);
    $time_end = explode(' ', microtime());
    $parse_time = number_format(($time_end[1] + $time_end[0] - ($time_start[1] + $time_start[0])), 3);
    echo '<span class="smallText">Current Parse Time: <b>' . $parse_time . ' s</span>';
    {/php}
    
    PHP:
    This method is displaying a time, but I'm not sure exactly how Smarty processes things, and whether this is really the parse time, or if processing happens outside of the templates.
     
    assembler, Jul 17, 2006 IP
  2. drewbe121212

    drewbe121212 Well-Known Member

    Messages:
    733
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    125
    #2
    it is all done through that code you posted above

    The first statement gets the current time at the start of the page, and saves it in a CONSTANT VARIABLE
    PAGE_PARSE_START_TIME
    1. [FONT='Courier New',Courier,monospace]{php}[/FONT]
    2. // The pages start time
    3. [FONT='Courier New',Courier,monospace]$time_start = explode(' ', PAGE_PARSE_START_TIME);[/FONT]
    4. // The time it currently is when the process stops
    5. [FONT='Courier New',Courier,monospace]$time_end = explode(' ', microtime());[/FONT]
    6. // Make it into a time formated number, determining total time by subtracting end from start
    7. [FONT='Courier New',Courier,monospace]$parse_time = number_format(($time_end[1] + $time_end[0] - ($time_start[1] + $time_start[0])), 3);[/FONT]
    8. // Echo it out.
    9. [FONT='Courier New',Courier,monospace]echo '<span class="smallText">Current Parse Time: <b>' . $parse_time . ' s</span>';[/FONT]
    10. [FONT='Courier New',Courier,monospace]{/php} [/FONT]
     
    drewbe121212, Jul 17, 2006 IP
  3. phper

    phper Active Member

    Messages:
    247
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    60
    #3
    Unless if the third party script is called by including it from within Smarty (e.g.: using {include_php} or {php}include(...);{/php}, doing the time calculation from Smarty will just calculate Smarty's parsing time. i.e.: not that useful.
     
    phper, Jul 18, 2006 IP
  4. assembler

    assembler Guest

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    phper,
    That is what I was questioning. There are no third party scripts being called from within the Smarty templates that I can see. Is there any way for me to tell if the number I am getting is just the Smarty parsing time?

    Thanks
     
    assembler, Jul 19, 2006 IP