我试图在使用 fwrite 写入文件之前和之后获取文件的最后修改时间。但是,出于某种原因,我得到了相同的值。
<?php
$i = filemtime('log.txt');
echo gmdate("h:i:s", $i);
echo "<br/>";
$e=fopen('log.txt', 'w');
fwrite($e, "well well well");
$j = filemtime('log.txt');
echo gmdate("h:i:s", $j);
?>
现在我在运行此脚本前大约一分钟用文本编辑器修改“log.txt”。所以我应该得到大约 40-60 秒的时差。如果有人能指出这里发生了什么,那将不胜感激。谢谢。
最佳答案
filemtime 的文档声明此函数的结果已缓存。也许你可以试试 clearstatcache :
<?php
$i = filemtime('log.txt');
echo gmdate("h:i:s", $i);
echo "<br/>";
$e=fopen('log.txt', 'w');
fwrite($e, "well well well");
clearstatcache();
$j = filemtime('log.txt');
echo gmdate("h:i:s", $j);
关于php - filemtime 在文件修改前后返回相同的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33973023/