5-minute file cache in PHP

前端 未结 8 1633
醉梦人生
醉梦人生 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:55

    I think you want some (psuedo code) logic like:

    if ($file exists) {
      if ($file time stamp older than 5 minutes) {
         $file = file_get_contents($url)
      }
    } else {
         $file = file_get_contents($url)
    }
    
    use $file
    

提交回复
热议问题