PHP Template tests

I am not a big fan of templating solutions for PHP.  The primary reason is because of Smarty.  Its not fast compared to straight PHP and, IMO, its not that much better than PHP syntax wise.  Its good for places where you need to force people to adhere to the MVC philosophy.

A coworker of mine found out about a project called Blitz.  its a PHP extension that does templating.  It will of course have one advantage over Smarty.  Smarty is slow as its all written in PHP.  PHP is slower than C and always will be.  Its just life.

So, Rob did some simple tests to see how Blitz, Smarty and plain old PHP perform.  I thought some folks (hey Jay) might be interested in this.


9 Responses to PHP Template tests

  1. All template systems are shite imo. require or include do just a good a job, and sepeparate out the logic and presentation. Oh and they’re as fast as you can get too.

  2. Marc Gear says:

    “all template systems are shite” is a bit of a wild generalisation Richard…

    I’ll agree with most systems that offer a different syntax to PHP (like smarty) are not really worth using unless you are using user input as templates (and therefore want to restrict the functionality) as they have a severe performance cost. However Blitz was 3x as fast as a regular PHP include in the the simple render test.

    Blitz seems like a really good option if you need a template language to deal with user-customisable pages.

  3. PHP essentially is a templating language (Value: ), so creating a templating language in a templating language never seemed logical to me. The main reason you here is you want to restrict functionality, which seems valid.

    But why the need to write a new parser for this with a completely different syntax. This doesn’t make the process easier for the user which write the templates. They most likely already know PHP. Creating an extension which does an include but restricts the use of functions and variables seems like a much nicer solution a much more fruitful way to spend your time, to me.

    Doing performance test really seems useless to me, because I don’t think there are a lot of sites where serving up the templates is the bottle neck. You see times as 0.0003 seconds (the last example isn’t real world), where the whole HTTP request handling, is measured in terms of 0.01 seconds.

    To conclude separation of concerns is a good idea, but why not write the templates in PHP.

  4. Alexey Rybak says:

    >>But why the need to write a new parser for this with a completely different syntax
    Modern applications have very complex presentation logic. We want HTML/JS guys to keep their hands off the presentation logic – we do know what happens otherwise. We want to separate HTML and view logic. We want to see the code, with no HTML/Smarty/PHP/Whatever spaghetti mess. We want to work with the code. Well, that is a some king of philosophy. You just feel this – or not :)))

    >>there are a lot of sites where serving up the templates is the bottle neck
    You are right. We are talking about a very small amount of projects: big and highload. Big enough to have problems while trying to manage PHP spaghetti with a small team which doesn’t want to grow – to be smart and agile. Highload enough to have tuned as much as possible finished with CPU on php-frontends being well not bottleneck but one of very important degrees of freedom.

  5. You can check out my templating solution for PHP5, it is based on include and plain PHP is used in templates. Still in development, but it is worth a look:

  6. Sorry for the wrong URI, here’s the right one:

  7. Brian Moon’s Blog: PHP Template tests (and Blitz)

  8. […] Moon points out a simple PHP templating application shown to him – Blitz: A coworker of mine found out about a […]

  9. kajal says:

    Hi , I am trying to mail Richard Heyes but always it get bounce, so please anybody can tell me right mail id, I want to ask him about php template class, It’s very urgent, please reply vaery soon.

%d bloggers like this: