The Clearstatcache () function clears the file state cache.
PHP caches the return information of some functions in order to provide higher performance. But sometimes, for example, if you check the same file multiple times in a script and the file is at risk of being deleted or modified during the execution of the script, you need to clear the file state cache to get the correct results. To do this, use the Clearstatcache () function.
Grammar
Clearstatcache ()
Hint: a function that will be cached, that is, the function affected by the Clearstatcache () 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 ()
The sample code for the Clearstatcache () function is as follows:
<?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 againcle arstatcache (); echo filesize ("test.txt");?>
The code above will output the following result:
792
100