Output file size, truncate file, clear cache, and then output file size again:
<?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");
?>
The output of the code above could be:
792
100
The clearstatcache() function clears the file status cache.
PHP caches data for some functions for better performance. If a file is to be checked several times in a script, you probably want to avoid caching to get correct results. To do this, use the clearstatcache() function.
clearstatcache(
clear_realpath_cache,
filename)
Parameter | Description |
---|---|
clear_realpath_cache | Optional. Indicates whether to clear the realpath cache or not. Default is FALSE, which indicates not to clear realpath cache |
filename | Optional. Specifies a filename, and clears the realpath and cache for that file only |
Tip: Functions that are caching:
Return Value: | Nothing |
---|---|
PHP Version: | 4.0+ |
PHP Changelog: | PHP 5.3 - Added two optional parameters: clear_realpath_cahe and filename |
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!