簡體   English   中英

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

[英]filemtime returns same value before and after modification of file

我正在嘗試使用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);

嘗試在fwrite之后添加fclose:

<?php
$i = filemtime('log.txt');
echo gmdate("h:i:s", $i);
echo "<br/>";
$e=fopen('log.txt', 'w');
fwrite($e, "well well well");
fclose($e);
$j = filemtime('log.txt');
echo gmdate("h:i:s", $j);
?>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM