This article introduces a simple entry to php-simple application of cache technology. If you need it, you can check it out. Here we use ob_start (); ob_end_flush ();.
| The Code is as follows: |
Copy code |
<? Php // Define the path and name of cached file $ Cachefile = 'cached-files/'. date ('m-d-y').'. php '; // Define how long we want to keep the file in seconds. I set mine to 5 hours. $ Cachetime = 18000; // Check if the cached file is still fresh. If it is, serve it up and exit. If (file_exists ($ cachefile) & time ()-$ cachetime <filemtime ($ cachefile )){ Include ($ cachefile ); Exit; } // If there is either no file OR the file to too old, render the page and capture the HTML. Ob_start (); ?> <Html> Output all your html here. </Html> <? Php // We're done! Save the cached content to a file $ Fp = fopen ($ cachefile, 'w '); Fwrite ($ fp, ob_get_contents ()); Fclose ($ fp ); // Finally send browser output Ob_end_flush (); ?> |