|
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 |
atu Smarty Regular
Joined: 18 Apr 2003 Posts: 51 Location: Luxembourg
|
Posted: Tue Aug 26, 2003 5:17 pm Post subject: max_cache_memory |
|
|
I propose the following script to prevent abuse of different cache id's to fill up server memory. This script count the size of every template output and add this value to a variable. If the size of this variable > 1000000 the cache is deleted.
Ref.: http://lists.php.net/article.php?group=php.smarty.general&article=10031
Code: |
/*
cache_memory.php contains a single variable "$cache_memory=0;"
*/
$output = $smarty->fetch( 'index.tpl', $_cache_id);
if(!$smarty->is_cached( 'index.tpl', $_cache_id ))
{
include 'configs/cache_memory.php';
$mem = $cache_memory + strlen($output);
if($mem > 1000000)
{
$smarty->clear_all_cache();
$mem = 0;
}
$_mem_content = "<?php \$cache_memory={$mem}; ?>";
$_fp = fopen('configs/cache_memory.php',"w");
$_action = fwrite($_fp,$_mem_content);
fclose($_fp);
}
|
This could be a usefull feature to add to smarty;
$smarty->max_cache_memory = 1000000;
Armand |
|
Back to top |
|
andre Smarty Pro
Joined: 23 Apr 2003 Posts: 164 Location: Karlsruhe, Germany
|
Posted: Wed Aug 27, 2003 5:50 am Post subject: |
|
|
Very nice idea. But I would enhance my Smarty class and overwrite the fetch() method to do this stuff for me. Then no changes to the existing templates will be needed. |
|
Back to top |
|
atu Smarty Regular
Joined: 18 Apr 2003 Posts: 51 Location: Luxembourg
|
Posted: Wed Aug 27, 2003 9:06 am Post subject: templates? |
|
|
Hi,
I cant see the relation with changes in templates?!?
Quote: | Then no changes to the existing templates will be needed. |
|
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Wed Aug 27, 2003 9:09 am Post subject: |
|
|
Perhaps andre meant that then it would be transparent and you wouldn't have to implement it for every fetch() / display() of a template |
|
Back to top |
|
andre Smarty Pro
Joined: 23 Apr 2003 Posts: 164 Location: Karlsruhe, Germany
|
Posted: Wed Aug 27, 2003 9:20 am Post subject: |
|
|
Yeah, thanks boots, andre meant this.
Too early and too much alcohol yesterday... forget about it. |
|
Back to top |
|
atu Smarty Regular
Joined: 18 Apr 2003 Posts: 51 Location: Luxembourg
|
Posted: Wed Aug 27, 2003 5:07 pm Post subject: The worst case |
|
|
Yes, I can understand now what andre mean. It depends of how your system is build up. If you call differnt templates through index.php?tpl=xxx you only need one fetch or dislplay for all templates.
But independent of this, abusing of different cacheid's of non existing pages is a problem of all sites that use smarty. So including a feature like:
$smarty->max_cache_memory = 1000000;
could prevent from the worst case. It could be a simpel and fast feature. On some systems, especially on cms systems, it's a lot of work to test if an url is what is seems to be. |
|
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
|