The clearstatcache() function clears the file status cache.
PHP caches return information from certain functions to provide higher performance. But sometimes, such as when you check the same file multiple times in a script and the file is in danger of being deleted or modified during the execution of the script, you need to clear the file status cache in order to get the correct results. To do this, use the clearstatcache() function.
clearstatcache()
Tip: Caching functions are functions affected by the clearstatcache() function:
stat()
lstat()
file_exists()
is_writable()
is_readable()
is_executable()
is_file()
is_dir()
is_link()
filectime()
fileatime()
filetime()
fileinode()
filegroup()
fileowner()
filesize()
filetype()
fileperms()
<?php//check filesizeecho filesize("test.txt");echo "<br />";$file = fopen("test.txt", "a+");// truncate fileftruncate($file,100) ;fclose($file);//Clear cache and check filesize againclearstatcache();echo filesize("test.txt");?>
The above code will output:
792100