The example & code of clearstatcache() in the PHP programming language.
If you are performing the multiple operations on the file using following functions stat(), lstat(), file_exists(), is_writable(), is_readable(), is_executable(), is_file(), is_dir(), is_link(), filectime(), fileatime(), filemtime(), fileinode(), filegroup(), fileowner(), filesize(), filetype(), and fileperms()., then the PHP will store cache in the memory. You need to clear the cache if you are using the these functions in the same php program multiple times. The following example explains how the clearstatcache() function can be used.
Syntax clearstatcache() Function in PHP
clearstatcache ([ bool $clear_realpath_cache = false [, string $filename ]] )
It clears or removes the file status value from the cache stored in the memory.
code for clearstatcache() in PHP
<?php
$a=fopen("c:/rose1/ram.txt","w");
echo "<br>file-size before clearstatcache() function ..<br>";
echo filesize("c:/rose1/ram.txt");
$p="welcome to roseindia\nwelcome to roseindia\nwelcome to roseindia\nwelcome to roseindia\nwelcome to roseindia\nwelcome to roseindia\n";
fwrite($a,$p);
clearstatcache();
echo "<br>file-size after clearstatcache() function ..<br>";
echo filesize("c:/rose1/ram.txt");
?>
output
file-size before clearstatcache() function ..
0
file-size after clearstatcache() function ..
126
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.