View previous topic :: View next topic |
Author |
Message |
andig Smarty Regular
Joined: 22 Apr 2004 Posts: 48
|
Posted: Sun Feb 14, 2010 1:04 pm Post subject: Smarty 3 migratin woes |
|
|
I've recently started upgrading videodb to Smarty3. The app makes heavy use of the template engine. Sofar I couldn't figure out these two errors:
Code:
$smarty->load_filter('output', 'trimwhitespace'); // remove whitespace from output
Error:
PHP Fatal error: Uncaught exception 'Exception' with message 'outputfilter "trimwhitespace" not callable' in D:\\htdocs\\videodb\\lib\\smarty\\sysplugins\\smarty_method_load_filter.php:32\nStack trace:\n#0 [internal function]: Smarty_Method_Load_Filter(Object(Smarty), 'output', 'trimwhitespace')\n#1 D:\\htdocs\\videodb\\lib\\smarty\\Smarty.class.php(534): call_user_func_array('smarty_method_l...', Array)\n#2 [internal function]: Smarty->__call('load_filter', Array)\n#3 D:\\htdocs\\videodb\\core\\functions.php(71): Smarty->load_filter('output', 'trimwhitespace')\n#4 D:\\htdocs\\videodb\\core\\session.php(16): require_once('D:\\htdocs\\video...')\n#5 D:\\htdocs\\videodb\\index.php(15): require_once('D:\\htdocs\\video...')\n#6 {main}\n thrown in D:\\htdocs\\videodb\\lib\\smarty\\sysplugins\\smarty_method_load_filter.php on line 32
Any this one.
Code:
<a href="http://www.videodb.net">v{$version|strip|replace:"_":"."|replace:" ":""}</a>
Error:
PHP Fatal error: Uncaught exception 'Exception' with message 'Syntax Error in template "templates/stylish2/header.tpl" on line 25 " <li><div id="logoversion"><a href="http://www.videodb.net">v{$version|strip|replace:"_":"."|replace:" ":""}</a></div></li>" unknown modifier "strip"' in D:\\htdocs\\videodb\\lib\\smarty\\sysplugins\\smarty_internal_templatecompilerbase.php:398\nStack trace:\n#0 D:\\htdocs\\videodb\\lib\\smarty\\sysplugins\\smarty_internal_compile_private_modifier.php(53): Smarty_Internal_TemplateCompilerBase->trigger_template_error('unknown modifie...')\n#1 [internal function]: Smarty_Internal_Compile_Private_Modifier->compile(Array, Object(Smarty_Internal_SmartyTemplateCompiler), NULL, NULL, NULL)\n#2 D:\\htdocs\\videodb\\lib\\smarty\\sysplugins\\smarty_internal_templatecompilerbase.php(258): call_user_func(Array, Array, Object(Smarty_Internal_SmartyTemplateCompiler), NULL, NULL, NULL)\n#3 D:\\htdocs\\videodb\\lib\\smarty\\sysplugins\\smarty_internal_templatecompilerbase.php(123): Smarty_Internal_TemplateCompilerBase->callTagCompile in D:\\htdocs\\videodb\\lib\\smarty\\sysplugins\\smarty_internal_templatecompilerbase.php on line 398
Both are working fine on latest 2x series.
Any ides?
Best regards,
Andreas |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Sun Feb 14, 2010 5:05 pm Post subject: |
|
|
It looks like that in both cases $smarty->plugins_dir does not point to the folder which does contain the output filter and modifer plugins. |
|
Back to top |
|
andig Smarty Regular
Joined: 22 Apr 2004 Posts: 48
|
Posted: Sun Feb 14, 2010 7:32 pm Post subject: |
|
|
Good catch!
I had setup smarty like this:
$smarty->plugins_dir = array('custom', 'plugins');
My directory is with smarty in lib/smarty and both plugin folders below that. Removing the plugin configuration works fine.
Now, trying
$smarty->plugins_dir[] = 'custom';
The app runs but doesn't find my custom function (Undefined Smarty method "_get_plugin_filepath"). Doing this
$smarty->plugins_dir[] = './lib/smarty/custom';
Leads to app not returning data anymore to the browser, yet no error.
I'm assuming the latter approach is correct and I'll need to dig closer into my custom functions?
Best regards,
Andreas |
|
Back to top |
|
andig Smarty Regular
Joined: 22 Apr 2004 Posts: 48
|
Posted: Mon Feb 15, 2010 8:19 am Post subject: |
|
|
Fixed the remaining issues. My plugin relied on _get_plugin_filepath which I've replaced with the following function from the forums:
/**
* Smarty helper function for Smarty 2/3 compatibility
*/
function smarty_require_plugin($folder, $plugin)
{
global $smarty;
if (method_exists($smarty, '_get_plugin_filepath')) {
//handle with Smarty version 2
require_once $smarty->_get_plugin_filepath($folder, $plugin);
} else {
//handle with Smarty version 3
foreach ($smarty->getpluginsdir($smarty) as $value) {
$filepath = $value ."/$folder.$plugin.php";
if (file_exists($filepath)) {
require_once $filepath;
}
}
}
}
The plugin directory has now changed to this:
$smarty->plugins_dir = array('./lib/smarty/custom', './lib/smarty/plugins');
Best regards,
Andreas |
|
Back to top |
|
andig Smarty Regular
Joined: 22 Apr 2004 Posts: 48
|
Posted: Wed Feb 17, 2010 4:25 pm Post subject: |
|
|
Now that I've got the functionality setup I've started looking into performance. Using a simple wget loop over the main pages of my application (http://videodb.net) I'm noticing that smarty3 behaves significantly slower that smarty2.
What I've measured is that 13 page fetches take 14 secs instead of 5 with smarty2. I've verified that my app does execute that same number of SQL statements (so I'm pretty confident that especially the migrated plugins have not changed their logic). I've also verified that both the v2 and v2 implementations still behave ok.
So my question is- where should I be looking for potential performance issues or are there any performance-related lessons learned from smarty upgrades?
Best regards,
Andreas
PS.: I'm not using caching at the moment. |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Wed Feb 17, 2010 5:32 pm Post subject: |
|
|
Andreas
Do you make use of the {eval} tag? Here could be a possible root of slower speed as the Smarty3 compiler is slower then the compiler of Smarty2. This on my list of investigations for improvent. |
|
Back to top |
|
andig Smarty Regular
Joined: 22 Apr 2004 Posts: 48
|
Posted: Thu Feb 25, 2010 1:24 pm Post subject: |
|
|
I've finally deployed my app to the server ([url]videodb.net/demo[/url]) and am faced with the final hurdle:
Fatal error: Uncaught exception 'Exception' with message 'Syntax Error in template "templates/elegant/show.tpl" on line 101 " <span class="img-shadow">{html_image file=$video.imgurl link=$link title=$lang.visit max_width="97" max_height="144" id="coverimg" class="canzoom" targetimg=$video.imgurl}</span>" unknown tag "html_image"' in /hp/aa/ad/gq/www/cpuidle-de/videodb/lib/smarty/sysplugins/smarty_internal_templatecompilerbase.php:398 Stack trace: #0 /hp/aa/ad/gq/www/cpuidle-de/videodb/lib/smarty/sysplugins/smarty_internal_templatecompilerbase.php(227): Smarty_Internal_TemplateCompilerBase->trigger_template_error('unknown tag "ht...', 101) #1 /hp/aa/ad/gq/www/cpuidle-de/videodb/lib/smarty/sysplugins/smarty_internal_templateparser.php(2142): Smarty_Internal_TemplateCompilerBase->compileTag('html_image', Array) #2 /hp/aa/ad/gq/www/cpuidle-de/videodb/lib/smarty/sysplugins/smarty_internal_templateparser.php(2530): Smarty_Internal_Templateparser->yy_r41() #3 /hp/aa/ad/gq/www/cpuidle-de/videodb/lib/smarty/sysplugins/smar in /hp/aa/ad/gq/www/cpuidle-de/videodb/lib/smarty/sysplugins/smarty_internal_templatecompilerbase.php on line 398
Apparently the plugins are not found. I've verified that the folder ist correct though, and setup is the same as on the development machine:
$smarty->plugins_dir = array('./lib/smarty/custom', './lib/smarty/plugins');
Does anybody have the lightest idea what the issue could be in this case?
Best regards and again thank you for the great support,
Andreas |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Thu Feb 25, 2010 1:58 pm Post subject: |
|
|
try absolute system paths |
|
Back to top |
|
andig Smarty Regular
Joined: 22 Apr 2004 Posts: 48
|
Posted: Thu Feb 25, 2010 2:19 pm Post subject: |
|
|
I did. Broke it down to the simplest test case possible:
Code: |
// put full path to Smarty.class.php
require('./lib/smarty/Smarty.class.php');
$smarty = new Smarty();
$smarty->template_dir = '.';
$smarty->compile_dir = './cache/smarty';
$smarty->cache_dir = './cache/smarty';
#$smarty->config_dir = '/web/www.domain.com/smarty/configs';
if (defined('SMARTY_DIR')) echo "SMARTY_DIR is defined: ".SMARTY_DIR."<br/>";
echo('plugins: ');
var_dump($smarty->plugins_dir);
echo "<br/>";
$smarty->assign('name', 'Ned');
$smarty->display('st.tpl');
|
<html>
<head><title>Smarty</title></head>
<body>
Hello, {$name}!
{html_image src="test.gif"}
</body>
</html>
All path names look fine:
SMARTY_DIR is defined: /hp/aa/ad/gq/www/cpuidle-de/videodb/lib/smarty/
plugins: array(1) { [0]=> string(55) "/hp/aa/ad/gq/www/cpuidle-de/videodb/lib/smarty/plugins/" }
Warning: substr_compare() [function.substr-compare]: The start position cannot exceed initial string length in /hp/aa/ad/gq/www/cpuidle-de/videodb/lib/smarty/sysplugins/smarty_internal_templatecompilerbase.php on line 146
Fatal error: Uncaught exception 'Exception' with message 'Syntax Error in template "./st.tpl" on line 8 "{html_image file="test.gif"}" unknown tag "html_image"' in /hp/aa/ad/gq/www/cpuidle-de/videodb/lib/smarty/sysplugins/smarty_internal_templatecompilerbase.php:398 Stack trace: #0 /hp/aa/ad/gq/www/cpuidle-de/videodb/lib/smarty/sysplugins/smarty_internal_templatecompilerbase.php(227): Smarty_Internal_TemplateCompilerBase->trigger_template_error('unknown tag "ht...', #1 /hp/aa/ad/gq/www/cpuidle-de/videodb/lib/smarty/sysplugins/smarty_internal_templateparser.php(2142): Smarty_Internal_TemplateCompilerBase->compileTag('html_image', Array) #2 /hp/aa/ad/gq/www/cpuidle-de/videodb/lib/smarty/sysplugins/smarty_internal_templateparser.php(2530): Smarty_Internal_Templateparser->yy_r41() #3 /hp/aa/ad/gq/www/cpuidle-de/videodb/lib/smarty/sysplugins/smarty_internal_templateparser.php(2630): Smarty_Internal_Templateparser->yy_reduce(41) #4 /hp/aa/ad/gq/www/cpuidle-de/videodb/lib/smarty/sysplugins/smarty_internal_smartytemplatecompi in /hp/aa/ad/gq/www/cpuidle-de/videodb/lib/smarty/sysplugins/smarty_internal_templatecompilerbase.php on line 398 |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Thu Feb 25, 2010 2:53 pm Post subject: |
|
|
Do any of the plugins work? You can also run a post-install test:
$smarty->test();
or with current beta 8 svn, $smarty->utilities->test(); |
|
Back to top |
|
andig Smarty Regular
Joined: 22 Apr 2004 Posts: 48
|
Posted: Thu Feb 25, 2010 3:12 pm Post subject: |
|
|
Mhm. Test thingy is happy:
Smarty Installation test...
Testing template directory...
. is OK.
Testing compile directory...
./cache/smarty is OK.
Testing plugins directory...
/hp/aa/ad/gq/www/cpuidle-de/videodb/lib/smarty/plugins/ is OK.
Testing cache directory...
./cache/smarty is OK.
Testing configs directory...
FAILED: ./configs/ is not a directory.
Tests complete.
Wondering if this is a permissions issue- do I have a chance to find out which plugins smarty actually found on startup?
Best regards,
Andreas |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Thu Feb 25, 2010 3:22 pm Post subject: |
|
|
See if PHP can read the plugin file?
Code: | readfile($smarty->plugins_dir[0]. 'function.html_image.php'); |
|
|
Back to top |
|
andig Smarty Regular
Joined: 22 Apr 2004 Posts: 48
|
Posted: Thu Feb 25, 2010 4:12 pm Post subject: |
|
|
It can... now I'm fully lost. |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Thu Feb 25, 2010 4:13 pm Post subject: |
|
|
Another note:
compile_dir and cache_dir should be different folders. |
|
Back to top |
|
andig Smarty Regular
Joined: 22 Apr 2004 Posts: 48
|
Posted: Thu Feb 25, 2010 6:09 pm Post subject: |
|
|
Shouldn't matter as I'm not using caching- and does not change the error message Would be happy to PM ftp login if interested.... |
|
Back to top |
|
|