Hi everyone! I have another weird question. I'm working on my site where the information won't be changing very often, and it's not horribly important that after a change that the information is currently available. With that said, I've started caching my sql calls as a JSON text file. This lead me to start thinking that maybe I should do that with my index file as well. Is there any real benefit to doing this? So instead of the user coming to my site and waiting for my server to do its looping and compiling, the file has already been cached and the markup is already available. I would think this would be faster but I can't imagine it being noticeable. Does anyone have any insight? Thanks!!
caching index.php file
Collapse
X
-
Tags: None
-
With that said, I've started caching my sql calls as a JSON text file.
So instead of the user coming to my site and waiting for my server to do its looping and compiling, the file has already been cached and the markup is already available. -
First off... Sending plain HTML is always going to be
faster than processing database records.
If the information really doesn't change that often,
why don't you just generate an HTML page and feed that
to the visitors?
You could check the generation date/time of the HTML
file and regenerate from the database if the generation
date/time is older than some defined value.
{ You could even use matches in an .htaccess file to do
the caching check and either feed a pre-generated HMTL
file or invoke the index.php script if generation is required. }
Just a thought...
Some pseudo code for checking inside of an index.php file...
Code:0- Entry point of index.php 1- Check file time of index.html 2- If time is within the defined caching time, feed the current index.html to the browser. 3- If time is older, regenerate the index.html using buffering, output to the browser, and overwrite the index.html file (Ensuring that only one visitor's request is overwriting the HTML file can be a little tricky and would more than likely require some type of semaphore or temp file to real file switch, but it's doable.)
Comment
Comment