views:

373

answers:

3

Hello

I am using PHPSavant templating system for a project and I am not sure how to use ob_start in this.

I have tried before .. for example,

page_header.php
-- ob_start();

page_footer.php
-- ob_end_flush();

But because now I am using a templating system.. am not sure where to put these function.

$template = new Savant3();
$template->some_var = $some_value;
$template->display('default_template');

the default_template contains all of and populate section using some variables (set to $template object). Should I be using ob_start and ob_end_flush where my html code is or to include on each and every php file which calls to this template?

Any ideas? thanks.

+1  A: 

I guess that display method actually outputs the template, so that's the one you should wrap with ob_start and ob_end_flush. However I don't really see advantage of using ob_end_flush around single function call.

Michal Čihař
+2  A: 

You don't have to force a flush, when the PHP script terminates the buffer is flushed.

As long as you put ob_start() at the beginning of your script, that's the best place. In fact you might want to force GZIP compression which will greatly speed up your page display. It seems most servers have GZIP disabled, but you can force it on in your PHP via:

ob_start('ob_gzhandler');
TravisO
actually main reason I want to use ob_start is to add this compression.