PHP clearstatcache() Function
Complete PHP Filesystem Reference Manual
Definition and Usage
The clearstatcache() function clears the file status cache.
PHP caches the return information of certain functions to provide better performance. However, sometimes - for example, when checking the same file multiple times in one script and that file may be deleted or modified during the script's execution - you need to clear the file status cache to get correct results. To do this, use the clearstatcache() function.
Syntax
clearstatcache()
Tips and Notes
**Tip:** The functions that are cached, i.e. those affected by clearstatcache():
- 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()
Example
"; $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
Complete PHP Filesystem Reference Manual