Supersimple static file based (html) php site cache

前端 未结 5 1042
长情又很酷
长情又很酷 2021-02-09 21:59

I have a website that basically only displays things without any forms and post-gets. This website is PHP based and hosted on shared hosting. It rarely changes. I would like to

5条回答
  •  遥遥无期
    2021-02-09 22:47

    It's a while since you asked this, but as this is still gathering search hits I thought I'd give you a better answer.

    You can do static caching in PHP without .htaccess or other trickery. I found this at http://simonwillison.net/2003/may/5/cachingwithphp/ :

    \n";
        exit;
    }
    ob_start(); // Start the output buffer
    
    /* The code to dynamically generate the page goes here */
    
    // Cache the output to a file
    $fp = fopen($cachefile, 'w');
    fwrite($fp, ob_get_contents());
    fclose($fp);
    ob_end_flush(); // Send the output to the browser
    ?>
    

提交回复
热议问题