The content shared with you in this article is about clearstatcache in php, which has certain reference value. Friends in need can refer to it
The function of clearstatcache() is to clear the file status cache.
PHP’s cached data is very beneficial for running functions faster and better. If a file is tested multiple times in a script, you may disable caching of correct results. To achieve this, you can use the
clearstatcache() function.
When using stat(), lstat(), or any of the functions listed in the affected functions table (see below),
PHP will cache the return information from these functions to provide faster performance. However, in some cases, you may
want to clear cached information. For example, if you check the same file multiple times in a script and the file is in danger of being deleted or modified during
the execution of this script, you need to clear the file status cache. In this case, you can use the clearstatcache() function to clear the file information cached by PHP.
It must be noted that PHP will not cache information for files that do not exist. So if
file_exists() is called to check for a file that does not exist, it will return
FALSE until the file is created. If the file is created, even if it is deleted later, it will return TRUE
Note: This function caches the information of a specific file name, so it only operates on the same file name multiple times and
requires the file information Clearstatcache() needs to be called only when it is not cached.
Syntax
clearstatcache()
Tips and Notes
Tip: Function that performs caching:
stat()
lstat()
file_exists()
is_writable()
is_readable()
is_executable()
is_file()
is_dir()
is_link()
filectime()
fileatime()
filemtime()
http://www.ibwen.com iBwen provides massive information to satisfy your thirst for knowledge!
All resources on this site are partially reproduced from the Internet! Copyright belongs to the author
http://www.ibwen.com
fileinode()
filegroup()
fileowner()
filesize()
filetype()
fileperms ()
Case
<?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 againcle arstatcache(); echo filesize("test.txt"); ?>
100
Related recommendations:
php clearstatcache() function usage details
The above is the detailed content of clearstatcache in php. For more information, please follow other related articles on the PHP Chinese website!