caching index.php file

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • fishnfrogs
    New Member
    • Nov 2009
    • 20

    caching index.php file

    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!!
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    With that said, I've started caching my sql calls as a JSON text file.
    are you sure this is actually faster?

    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.
    that essentially depends on how fast the compiling is. if it is, say, under 500 ms (which is quite long for a script), caching is not worth the effort (the transfer time (Request + Response) is usually some 100 ms). however, the more visitors you have per hour, the more useful caching can be.

    Comment

    • dgreenhouse
      Recognized Expert Contributor
      • May 2008
      • 250

      #3
      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

      Working...