Monday, March 25, 2013

Output Buffering using php


PHP - Caching Pages with Output Buffering

There are 3 Following  basic functions you can use It.


ob_start() any output will be saved in PHP's internal buffer and not yet printed to the screen. This includes HTML and echoed or printed php statements. Header statements are the exception as they are still sent to the browser.


<?php
ob_start(); // Turns on output buffering
?> 



 ob_get_contents() will return a string value of the current contents of the buffer. This will prove very useful for caching purposes when placed at the end of pages. More on that in a bit.



<?php
// Stores the contents of the buffer in a variable as a string
$contents = ob_get_contents();
?>


 ob_end_flush() will print all the contents of the buffer just as you would expect to see it if output buffering was never turned on.


<?php
ob_end_flush(); // Turn off buffering and print the contents
?> 

No comments:

Post a Comment