在修改文件前后,filemtime返回相同的值

Hai*_*Ali 4 php fopen timestamp fwrite filemtime

我正在尝试使用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);

?>
Run Code Online (Sandbox Code Playgroud)

现在,在运行此脚本大约一分钟之前,我使用文本编辑器修改了“ log.txt”。所以我应该得到大约40-60秒的时差。如果有人指出这里发生了什么,那将是非常感谢。谢谢。

The*_*ird 5

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);
Run Code Online (Sandbox Code Playgroud)