在修改文件前后,filemtime返回相同的值 [英] filemtime returns same value before and after modification of file

查看:87
本文介绍了在修改文件前后,filemtime返回相同的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试获取使用fwrite写入文件之前和之后文件的最后修改时间.但是,由于某种原因,我得到了相同的值.

Im trying to get the last modified time of a file before and after i write to it using fwrite. But, i get the same values for some reason.

<?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秒的时差.如果有人指出这里发生了什么,那将是不胜感激的.谢谢.

Now i modify 'log.txt' with a text editor about a minute before i run this script. So i should be getting about 40-60 seconds of time difference. If someone could point out what is happening here, that'd be really appreciated. Thanks.

推荐答案

filemtime 的文档指出此功能被缓存.也许您可以尝试使用 clearstatcache :

The documentation of filemtime states that results of this function are cached. Maybe you can try it with 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);

这篇关于在修改文件前后,filemtime返回相同的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆