Definition and Usage
clearstatcache () function clears the file status cache.
PHP will return cached information for certain functions in order to provide higher performance. But sometimes, like checking the same file multiple times in a script, and the script file during the execution risk of being deleted or modified, you need to clear the cache file status, in order to obtain correct results. To do this, use the clearstatcache () function.
grammar
clearstatcache()
Tips and Notes
Tip: function caching, namely by clearstatcache () function affects the function:
- 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()
Examples
<?php //check 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 above will output: