Using mod_rewrite to serve cached page directly

Hi,

I seriously consider switching from Rails to Yii, but there is something I used a lot with RoR which seems to be missing. It is the possibility to cache full pages into .html files that Apache can serve directly (that is statically). This results in dramatic performance enhancements.

With RoR, when let us say a cache-enabled page "/posts/42" is first generated, a file is statistically created ("/posts/42.html") so that for the next requests, Apache will check whether this file exists or not. If it exists, Apache serves it directly through mod_rewrite, without even waking up the PHP script. If it does not, the request is forwarded to the PHP script.

Is there a simple way to do this with Yii? I would love this feature to be implemented, but any hint on how to start implementing it myself would be great too!

Thanks a lot,

Nauhaie

PS: This is a question about Yii creating these static files, not about Apache config, which is no problem.

Try following in your config (you’ll need to decide how to name your files):




'onBeginRequest'=>create_function('$event', 'return ob_start();'),

'onEndRequest'=>create_function('$event', '$out=ob_get_flush();file_put_contents($fileName, $out); return $out;')



I guess it’s going to be hard to find something simpler than this :wink:

Thanks a lot!

Nauahaie