filemtime returns same value before and after modification of file

后端 未结 2 1623
渐次进展
渐次进展 2021-01-19 15:59

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.



        
相关标签:
2条回答
  • 2021-01-19 16:28

    Try to add fclose after the fwrite:

    <?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);
    ?>
    
    0 讨论(0)
  • 2021-01-19 16:31

    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);
    
    0 讨论(0)
提交回复
热议问题