php html cache

Vector logo of the PHP programming language wi...

Today I will scratch a light reading about PHP Cache Of Html. We're talking about caching the output of our code, not as I've written to cache the spikes to OpCode Level with eAccelerator. So what's the speech – Let us remember the rapid work of PHP. We submit a request to Web server-A US he accepts the parameters we submit then he submits them to the PHP script he compiles and spits the result in HTML version. This is in pretty general terms. What would be our idea here to skip orders?, To jump over large blocks or not such large blocks as we directly paint the already compiled output. The advantages are obvious – Reduction in the execution time, By less load and resource consumption. Generally it is not discovering the hot water nor is it something who knows how complicated. There are many classes for this purpose as PHP Pear Cache_Lite which has great functionality but I think in the future I will write my own with a rather more streamlined structure and my own caching requirements. Now we will look at the Aboriginal version with Output Control Functions. So let's cache something –

//start cache all output after that will be saved

ob_start();

//generate output

echo 'Some dynamic output';

echo 'Some other dynamic output ...';

//assign output into variable

$var=ob_get_contents();

//close cache output

ob_end_flush();

The above code is trivial but let's explain what happened. First we declare which part in the code starts caching. Then we generate the output from the code in a standard way. The generated output is then joined to a variable that will be available later whether through a file any or sessions this is your decision. Finally, we clear and disable caching. A very trivial operation, if we say cache geoscanning goes through huge blocks of code so we can save a lot of CPU time by caching for a while or for a single session. It's now all about what you want whether to public the cache or be available to a different user.

Enhanced by Zemanta

Leave a Reply

Your email address will not be published. Required fields are marked *

Anti SPAM *