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

标签 php timestamp fopen 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);

?>

现在我在运行此脚本前大约一分钟用文本编辑器修改“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/

相关文章:

php - 是否可以按找到的匹配项数量对与 REGEX 匹配的 SQL 查询进行排序?

Javascript,如何找到mysql时间戳样式中两个日期时间之间的差异

apache-kafka - 在Kafka中如何根据生产时间获得确切的偏移量

c++ - fwrite 似乎没有复制整个文件(只是开始)

php - 使用 Memcached/Elasticache 的 Nginx 全页缓存并使用 PHP 进行清除

PHP:使用单词 'and' 的语法是什么意思?

php - 后台刷新动态数据

mysql - sql where 子句中的最后 n 个工作日

创建一个在 C 中作为参数传递的文件

c++ - GLSL shader based on KNN of external file (open external file from .vert or .frag)