Jump to content

PHP File Caching Question


kelsheikh

Recommended Posts

Hi I just have a question about the caching code below.

 

Should the date function be in the filename if I want to cache the file for several days? Or if the date changes will a new file be created and used instead of the the previous cache file. Is that not even used since my if statement checks for the file modification time? Thanks for the help in understanding this.

    $cachefile = 'cache/cached/'.$id . date('M-d-Y').'.php';
    $cachetime = 172800;

    // 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;
    }
    ob_start();

{HTML TO CACHE}

    $fp = fopen($cachefile, 'w');
    fwrite($fp, ob_get_contents());
    fclose($fp);
    // finally send browser output
    ob_end_flush();

I basically want to cache a file for 2-3 days.

Link to comment
https://forums.phpfreaks.com/topic/288448-php-file-caching-question/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.