PHP clearstatcache() 函数

盼什么没什么,怕什么来什么。那些忙于批评别人的人,都忘了检讨自己。生活就是这样,当你想昂着头走路时,你就得随时准备在地上趴着。

clearstatcache() 函数会缓存某些函数的返回信息,以便提供更高的性能。但是有时候,比如在一个脚本中多次检查同一个文件,而该文件在此脚本执行期间有被删除或修改的危险时,你需要清除文件状态缓存,以便获得正确的结果。要做到这一点,就需要使用 clearstatcache() 函数。

PHP clearstatcache() 函数

clearstatcache() 函数清除文件状态缓存。

语法:

clearstatcache()

例:

<?php
//检查文件大小
echo filesize("test.txt");
$file = fopen("test.txt", "a+");
// 截取文件
ftruncate($file,100);
fclose($file);
//清除缓存并再次检查文件大小
clearstatcache();
echo filesize("test.txt");

输出结果:792   100

会进行缓存的函数,即受 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()

到此这篇关于PHP clearstatcache() 函数就介绍到这了。非学无以广才,非志无以成学。更多相关PHP clearstatcache() 函数内容请查看相关栏目,小编编辑不易,再次感谢大家的支持!

您可能有感兴趣的文章
PHP性能优化案例分享

PHP实现短信验证码的发送次数限制

PHP中的异常处理机制深入讲解

PHP常见七种算法合集代码实例

PHP微信扫描二维码关注公众号后自动登录第三方网站