Login   Register  
PHP Classes
elePHPant
Icontem

File: smarty/test_06_smarty.tpl

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Dragan Bo?njak  >  Cache output and objects  >  smarty/test_06_smarty.tpl  >  Download  
File: smarty/test_06_smarty.tpl
Role: Auxiliary data
Content type: text/plain
Description: Templage for smarty plugin example
Class: Cache output and objects
Cache the output of PHP scripts in files
Author: By
Last change:
Date: 2007-03-28 07:31
Size: 1,324 bytes
 

Contents

Class file image Download
<i>Smarty plugin test</i><br><br>

{cache file="cache.smarty_example.tmp" time="20"}
	<b>Hello Smarty!</b><br>
	In cached part it's {$date}<br>
	<i>This part will expire in 20 s</i><br>
	Output is stored in <b>./cache.test_01.tmp</b><br><br>
	
	{php}
		
		function microtime_float()
		{
		   list($usec, $sec) = explode(" ", microtime());
		   return ((float)$usec + (float)$sec);
		}
		
		
		function bcpi($precision=30){
		        $accuracy = ($precision+5)*45/32;
			//accuracy worked till the 180th $precision, almost used 30 second to calculate
			    bcscale($precision+5);
			    $n = 1;
			    $bcatan1 = 0;
			    $bcatan2 = 0;
			    while($n < $accuracy){
			//atan functions
			        $bcatan1 = bcadd($bcatan1, bcmul(bcdiv(pow(-1, $n+1), $n * 2 - 1), bcpow(0.2, $n * 2 -1)));
			        $bcatan2 = bcadd($bcatan2, bcmul(bcdiv(pow(-1, $n+1), $n * 2 - 1), bcpow(bcdiv(1,239), $n * 2 -1)));
			        ++$n;
			    }
		    return  bcmul(4,bcsub(bcmul(4, $bcatan1),$bcatan2),5);
		}
		
		$time = microtime_float();
		
		$pi = bcpi(40);
		echo("<b>pi = ".$pi."</b><br><br>");
		echo("<b>This part is executed every 10 seconds</b><br>");
		echo("<b>Time of execution: <u>".(microtime_float() - $time)." s</u></b><br><br>");


	{/php}
	
{/cache}

<b>This part is executed every time</b><br>
Real time is {$date}<br>