Friday, 15 February 2013

How can I cache a dynamic page to a flat file in PHP? -


I am trying to roll the caching system to reduce the load on the database.

I want

this code is here:

  $ cache_file = ""  

$ _GET ['page_id'] '. Html '; Function cache () {// Here I want to get a timestamp of the file which was previously cached, // if it exists // if the file does not exist, then create it // if it exists, then the last modified Check the time, if it is too long, overwrite the file / file $ Ob = ob_get_contents (); File_put_contents ($ cache_file, $ ob); } Function loadFromCache ($ page_id) {$ file_name = $ page_id '.html'; If (! File_exists ($ file_name)) {return false; } Readfile ($ file_name); Back true; }

Thanks.

You can use the modification time for the file to receive.


No comments:

Post a Comment