Php/func filesystem clearstatcache
来自菜鸟教程
PHP clearstatcache()函数
例
输出文件大小,截断文件,清除缓存,然后再次输出文件大小:
<?php
//output filesize
echo filesize("test.txt");
echo "<br />";
$file = fopen("test.txt", "a+");
// truncate file
ftruncate($file,100);
fclose($file);
//Clear cache and check filesize again
clearstatcache();
echo filesize("test.txt");
?>
上面代码的输出可能是:
792 100
定义和用法
clearstatcache()函数清除文件状态缓存。
PHP为某些功能缓存数据以获得更好的性能。如果要在脚本中多次检查文件,则可能要避免缓存以获取正确的结果。为此,请使用clearstatcache()函数。
句法
clearstatcache(clear_realpath_cache, filename)
参数值
| 参数 | 描述 |
|---|---|
| clear_realpath_cache | 可选的。指示是否清除实路径缓存。默认值为FALSE,表示不清除真实路径缓存 |
| filename | 可选的。指定文件名,并仅清除该文件的真实路径和缓存 |
提示与注意
Tip: 正在缓存的功能:
技术细节
| 返回值: | 没有 |
| PHP版本: | 4.0+ |
| PHP更新日志: | PHP 5.3-添加了两个可选参数:
clear_realpath_cahe and filename |