|
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 |
sm@rty Smarty Regular
Joined: 01 Oct 2014 Posts: 65
|
Posted: Sun Jan 11, 2015 10:51 am Post subject: ticks in smarty ! |
|
|
hi
best way for limitation memory usage or manage output length for users is using ticks in smarty.(what your solution ?)
but have a problem with ticks in smarty.
if i using tick like this example :
Code: |
$GLOBALS['SmartyStartTick'] = false;
register_tick_function(function(){
if($GLOBALS['SmartyStartTick'])
{
//my code for verify limitation
}
});
declare(ticks=1);
$GLOBALS['SmartyStartTick'] = true;
$smarty->display('eval:tpl');
$GLOBALS['SmartyStartTick'] = false;
//some code php
|
this example included proccess smarty and template but i want only include proccess template.(ticks only for template)
Is it enforceable?
---------------------------------
translator helper : google |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Sun Jan 11, 2015 9:06 pm Post subject: |
|
|
I think you are missing one small point.
Smarty processing include 3 steps, not 2.
1. Template compilation.
2. Template substitution.
3. Template output.
The first step is cached by default, unless you request force recompilation.
The second step may be cached.
The third step is the output itself and of course can not be cached. |
|
Back to top |
|
sm@rty Smarty Regular
Joined: 01 Oct 2014 Posts: 65
|
Posted: Mon Jan 12, 2015 7:22 am Post subject: |
|
|
thanks for reply.
Quote: | Smarty processing include 3 steps, not 2.
1. Template compilation.
2. Template substitution.
3. Template output. |
I did not know. thanks.
i want all the ticks fire in user template.
for example :
Code: |
{$a = 1} // tick 1 start
{$b = 2} // tick 2 start
{$b = 3} // tick 3 start
|
this code include 3 ticks. i want this 3 tick ! it's possible ? |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Mon Jan 12, 2015 3:33 pm Post subject: |
|
|
Sorry, but from your description it is not very clear for me, what you want to do.
May be someone else will be able to assist you. |
|
Back to top |
|
sm@rty Smarty Regular
Joined: 01 Oct 2014 Posts: 65
|
Posted: Tue Jan 13, 2015 10:00 am Post subject: |
|
|
no problem please executed this php code :
Code: |
$GLOBALS['tickStart'] = false;
register_tick_function(function($maxUsage){
if(!$GLOBALS['tickStart']) return;
$realMemoryUsageOfUser = memory_get_usage() - $GLOBALS['tickStart'];
echo 'Memory Usage : '.$realMemoryUsageOfUser.' Byte !<br>';
if($realMemoryUsageOfUser > $maxUsage)
exit('<span style="color:red">Warning : Allowed Memory is '.$maxUsage.' byte !</span>');
/*
for example :
in between timestamp 1 and 2 user allowed memory is 10 kb (in microsecond)
*/
},376);
declare(ticks=1){
$GLOBALS['tickStart'] = memory_get_usage();
$a = 1; echo '<span style="color:green">line 1 executed.</span><br>';
$b = 'abcdef'; echo '<span style="color:green">line 2 executed.</span><br>';
$c = rand(1,9); echo '<span style="color:green">line 3 executed.</span><br>';
for($i=0; $i<1000; $i++); echo '<span style="color:green">line 4 executed.</span><br>';
$GLOBALS['tickStart'] = false;
};
|
in above example in line 4 (real line is 19) execution is stop and this way can be effective in ddos attack !
example of smarty php compile file in compile directory (in my think):
Code: |
register_tick_function('myfunc');
declare(ticks=1){
// php code in template after compile with smarty
}
unregister_tick_function('myfunc');
|
ok ? |
|
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
|