Supersimple static file based (html) php site cache

前端 未结 5 1058
长情又很酷
长情又很酷 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:45

    Just to add a little more to nico's response to make it more useful for generic copy and paste use by saving the time of typing in individual cachefile names for each file saved.

    Original:

    $cachefile = 'cache/index-cached.html';
    

    Modified:

    $cachefile = $_SERVER['DOCUMENT_ROOT'].'/cache/'.pathinfo($_SERVER['SCRIPT_NAME'], PATHINFO_FILENAME).'-cached.html';
    

    What this does is to take the filename of whatever file it is located in, minus the extension (.php in my case), and appends the "-cached.html" label and new extension to the cached file. There are probably more efficient ways of doing this, but it works for me and hopefully save others some time and effort.

提交回复
热议问题