2017-11-17 245 views
-1

目前,我每天緩存文件,但我如何緩存這個文件每週一次,例如星期天?我不知道如何繼續。緩存一個文件,如果它是某一天

if(time() - filemtime($cache) > 86400){ 
    $result = file_get_contents($url); 
    file_put_contents($cache, serialize($result)); 
    $flux = json_decode($result); 

}else{ 
    $result = unserialize(file_get_contents($cache)); 
    $flux = json_decode($result); 
} 
+0

cron作業可能? –

回答

1

使用運行每個星期天cron作業:

0 10 * * 0 php /path/to/cache_file.php 

cache_file.php腳本會是什麼樣子:

<?php 
$url = "http://...."; 
$cache = "/path/to/cache"; 
$result = file_get_contents($url); 
file_put_contents($cache, serialize($result)); 
+0

對不起,英語不是我的母語。我錯過了。實際上,我想每週緩存一次文件,例如星期天的10點。 – Garrosh

+0

我已經展示瞭如何用cron作業來做到這一點。 – Barmar

相關問題