2017-11-17 246 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

相关问题