php - 尽管对文件进行了更改,但 filemtime() 在执行期间保持不变

标签 php filemtime

尝试运行

<?php
  echo filemtime("test.txt")."\n";
  sleep(4);
  file_put_contents("test.txt", "test");
  echo filemtime("test.txt")."\n";
?>

对我来说命令行打印:

1343490984
1343490984

这不可能吧?

最佳答案

来自filemtime documentation :

Note: The results of this function are cached. See clearstatcache() for more details.

在再次调用 filemtime() 之前,您需要先调用 clearstatcache():

echo filemtime("test.txt")."\n";
sleep(4);
file_put_contents("test.txt", "test");
clearstatcache();
echo filemtime("test.txt")."\n";

关于php - 尽管对文件进行了更改,但 filemtime() 在执行期间保持不变,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11702553/

相关文章:

javascript - 我如何将这个 'x' 数量的方格居中?

php - Mysqli/PHP-显示具有特定值的行数/列中的总行数=百分比

php - 如何更改 Laravel 中 Vite list 的目录,或者如何在 Laravel 应用程序中提供两个 Vite 项目?

PHP递归文件文件夹扫描按修改日期排序

php - 如何在 PHP 中使用 filemtime 函数?

php - 使用 filemtime() 和 usort() 对文件进行排序会给出随机结果

PHP filemtime vs MySQL 最后更新时间戳用于 CMS 中的图像缓存

php - 了解 php 命令行脚本路径的可靠方法是什么?

CSS 解析器 - 插入时间

php - 创建采用数组的 SQL 查询