Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

PHP clearstatcache() Function

PHP clearstatcache() Function


PHP Filesystem Reference Manual 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():


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


PHP Filesystem Reference Manual Complete PHP Filesystem Reference Manual