clearstatcache in php

不言
Release: 2023-03-23 21:10:02
Original
2119 people have browsed it

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");
?>
Copy after login

The above code will output the following results:

792

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!