Re: [PHP-PEAR] Output_Cache Module

[email protected] (Ulf Wendel) Fri, 23 Feb 2001 10:58:23 +0100
Newsgroups php.pear
Message-ID <[email protected]>

Graeme Merrall wrote:
> Has anyone considered Smarty in the scheme of PEAR? Smarty already uses some
> PEAR elements for processing and AFAIK was derived as part of the effort to
> implement templates in the PHP engine.
> http://www.phpinsider.com/php/code/Smarty/

Smarty is something between a preprocessor and simplified XSLT. 

The preprocessor is helpful (compiling the templates) if you have static
input, but hey if you're input is static why using a template over a PHP
script? Every upto date HTML editor can handle <?php code ?> blocks and
hide the logics in your script from the user. As far as I understood the
compile stuff in Smarty translates the template into PHP code. Ok, let's
try to figure out what happens if you have database content:

PHP skript:
  - do the DB handling
  - loop through the result set and store all results into an array
  - pass the array to Smarty using assign()

Smarty:
  - translate (compile) the template into PHP
  - run the generated PHP

The classical way would be a preg_replace_all(). I'm not 100% sure, but
I doubt that Smarty wins the race as all preg_* functions can be damn
fast (less but linear time needed!), even faster as the str_* functions
and you don't have the compile logic. The runtime of str_*/preg_* is
negliable as long as your replacements are quite small (name, color,
date, ...). The functions get "slow" if you have big replacements of
several kb but even with them it's fast. This
http://www.redsys.de/schulung/core/index.php page does not use any cache
and runs at a mass hoster called Puretec (PHP4, MySQl, 5 .de domains,
... DM 20,-- (~$8 USD) / month). cat /etc/passwd shows 20830 entries.
Most time I get runtimes like these - total runtime: ~0.05s, IT[X]
~0.005s, Menu 3 ~0.01s.  

Smarty is quite complex and fat. Without inline docs the size of Smarty
is about 50k compared to 8k PHPLib Template, 12k IT, 12 + 14k IT[X]. Of
course you can't compare these figures as the systems offer different
features.

Don't try to copy XSLT. Smarty puts lots of the script logic into the
template. This leads to some kind of script language in the template.
It's not much of a difference to learn the properitary smarty scripting
language or the open standard simplified XSLT. The point is, that you
have to teach your webdesigner something completely new. Why not teach
the future: XSLT?

The Cache is really a nice idea, but you can rebuild the feature using
the Cache stuff. 

Although I don't like the conzept of Smarty it might be a good idea to
check it in to PEAR.

Ulf