PHP clearstatcache () function
Definition and Usage
clearstatcache () function clears the file status cache.
PHP caches information returned some function to provide higher performance. However sometimes, such as in a script to check the same file multiple times, and the file during script execution in danger of being dropped or modified, you need to clear the cache file status, in order to obtain correct results. To do this, use clearstatcache () function.
grammar
clearstatcache()
Tips and Notes
Tip: caching function, namely by clearstatcache () function is a function of the impact:
- 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");
?>
//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 code above will output:
792
100
100
Complete PHP Filesystem Reference Manual