php filemtime定时生成文件代码
filemtime() 函数返回文件内容上次的修改时间,若成功,则时间以 Unix 时间戳的方式返回,若失败,则返回 false。
语法:filemtime(filename)
<?php
$path = "a.txt";
if (file_exists($path)) {
$filetimes = filemtime($path);
$cutime = time();
$uptime = 900; //15分钟生成一次
if ($cutime - $filetimes > $uptime) {
$h = fopen($path, 'w+');
fwrite($h, '到了更新的时间');
fclose($h);
}
} else {
$h = fopen($path, 'w+');
fwrite($h, '文件不存在');
fclose($h);
}
本文地址:http://www.phprm.com/wenjian/fs987.html
转载随意,但请附上文章地址:-)