PHP clearstatcache() ফাংশন
Definition and Usage
The clearstatcache() function clears the file status cache.
The clearstatcache() function caches the return information of some functions to provide higher performance. However, sometimes, for example, when checking the same file multiple times in a script, and there is a risk that the file may be deleted or modified during the execution of the script, you need to clear the file status cache to obtain the correct result. To do this, you need to use the clearstatcache() function.
Functions that will be cached, i.e., affected by 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()
Syntax
clearstatcache()
Example
<?php // Check file size echo filesize("test.txt"); $file = fopen("test.txt", "a+"); // Cut file ftruncate($file,100); fclose($file); // Clear cache and check file size again clearstatcache(); echo filesize("test.txt"); ?>
Output:
792 100