zoukankan      html  css  js  c++  java
  • php filesize() 方法返回的文件大小异常

    问题描述:需要生成一个 700k 大小左右的文件,相关代码如下:

    <?php
        $handle = fopen('./split.log', 'a+');
        $result = 0;
        while( $result <= 700*1024) {
            for($number = 0; $number <= 10; $number++) {
                fwrite($handle, "{$number}	");
            }   
            fwrite($handle, "
    ");
            $result = filesize('./split.log');
            echo $result,"
    ";
            sleep(2);
        }   
        fclose($handle);
    ?>

    但是发现文件的大小一直不变,输出如下:

    问题原因:

    PHP 将缓存下面这些函数的返回信息以提供更快的性能。然而在某些情况下,你可能想清除被缓存的信息。例如如果在一个脚本中多次检查同一个文件,而该文件在此脚本执行期间有被删除或修改的危险时,你需要清除文件状态缓存。这种情况下,可以用 clearstatcache() 函数来清除被 PHP 缓存的该文件信息。

    stat(), lstat(), file_exists(), is_writable(), is_readable(), is_executable(), is_file(), is_dir(), is_link(), filectime(), fileatime(), filemtime(), fileinode(), filegroup(), fileowner(), filesize(), filetype() 和 fileperms()。

    详细信息可以查询  php 官方文档对于  clearstatcache() 方法的说明,链接为:http://www.php.net/manual/zh/function.clearstatcache.php

  • 相关阅读:
    泛型
    java unicode补充字符带来的码点和代码单元问题
    GIT相关
    Html5 Canvas学习
    解决animate动画连续播放bug
    自定义对象级别的组件开发
    关于常用却忘记的css,jQuery
    json格式初涉
    ajax
    jquery.validation.js的自定义方法
  • 原文地址:https://www.cnblogs.com/smallrookie/p/7211348.html
Copyright © 2011-2022 走看看