Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Eval instead of include

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Feature Requests
View previous topic :: View next topic  
Author Message
anicula
Smarty n00b


Joined: 07 Apr 2008
Posts: 3

PostPosted: Mon Apr 07, 2008 2:20 pm    Post subject: Eval instead of include Reply with quote

I have a project with templates that are loading multiple times. (one template is loading 30 times - using {include file="..."}) - my problem is that this is taking some time so I've done some tweaking to the smarty class - "replaced" php include with eval.

1. i've added a new var:
var $nds_cache_include = array();// cache for included files
2.Changed _include function like this:
function _include($filename, $once=false, $params=null){
if ($once) {
return include_once($filename);
} else {
if($this->nds_cache_include["$filename"] == null){
$content = file_get_contents("$filename");
$this->nds_cache_include["$filename"] = $content;
} else{
$content = $this->nds_cache_include["$filename"];
}
return eval('?>' . $content);
//return include($filename);// this was the onld code
}
}

and using _include function where the include(...) was used on fetch function and _smarty_include function

The execution time is 2/3 times faster.
Maybe in the futures someone who know smarty code will do a better job.

PS:I'm a newbie to smarty code = I'm using smarty not changing it, never done a plug in Smile
If there are someone that knows a better solution with the include problem - PLEASE let me know.
Back to top
View user's profile Send private message
looka
Smarty Rookie


Joined: 24 May 2008
Posts: 11

PostPosted: Wed May 28, 2008 4:59 pm    Post subject: Reply with quote

i have one better idea. php to include about 100rows file (.tpl files are parsed into ordinary php code) takes a few miliseconds.
evaluating anything takes at least 10 times more... so (my opinion):

do not use eval().
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Feature Requests All times are GMT
Page 1 of 1

 
Jump to:  
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
Protected by Anti-Spam ACP