Thursday, February 25, 2010

Fast & efficient Smarty view renderer for Yii Framework

Working with online games and especially PenguinFarmer and using Yii Framework I've been driven to solve a problem with Smarty view renderers available already on the internet.

Smarty was a required template engine by the web designers, so I should have found a way to optimize the plugin or just write a new one.

And here it is. Fast, efficient and tested on a huge traffic.
One of the first problems I faced wa that the regular Smarty renderers do failer when there were huge amount of traffic as they render the template then saves it into a temp file ready for the PHP renderer mechanism which Yii has.
There are major issues here which cause unnecessary overhead.

1) Why do we need to save the rendered view template? This is a unnecessary disk I/O
2) Why do we need to read the smarty parsed temp file again to parse it as a PHP template? Again unnecessary disk I/O
3) When there is a lot of traffik there is a gap between writing a smarty template and reading it again. So many times there were a blank pages or wrong smarty templates. Even with fast HDDs there we enought time between reads and writes so we can get problems.

After going throught the code, optimizing it and testing I am glad to present you a good and reliable Smarty view renderer for Yii Framework that you can use as a drop in replacement for your current one.

No comments:

Post a Comment