5-minute file cache in PHP

前端 未结 8 1605
醉梦人生
醉梦人生 2020-12-07 17:24

I have a very simple question: what is the best way to download a file in PHP but only if a local version has been downloaded more than 5 minute ago?

In my actual ca

8条回答
  •  再見小時候
    2020-12-07 17:54

    Try phpFastCache , it support files caching, and you don't need to code your cache class. easy to use on shared hosting and VPS

    Here is example:

    get($url);
    
    if($content == null) {
         $content = file_get_contents($url);
         // 300 = 5 minutes 
         $cache->set($url, $content, 300);
    }
    
    // use ur $content here
    echo $content;
    

提交回复
热议问题