通过touch()更改文件的上次修改时间,并使用filemtime()获取结果

Rid*_*thi 7 php caching

所以我试图获取文件的最后修改日期,然后将其更新到当前时间,但是当我查看结果时,我在$ oldtime和$ newtime中获得了SAME时间戳

$file = 'test.txt';
$oldtime = filemtime($file);
touch($file, time());
$newtime = filemtime($file);

echo '<h1>old</h1>';
print_r(getdate($oldtime));
echo '<h1>new</h1>';
print_r(getdate($newtime));
Run Code Online (Sandbox Code Playgroud)

dev*_*ler 14

clearstatcachetouch文件之后使用以获得适当的修改时间值.

因为您之前使用filemtime过,结果是缓存了,在第二次调用时,结果从该缓存中拉出而不是直接检查文件.