您现在的位置: 365建站网 > 建站教程 > PHP 教程 > PHP clearstatcache() 函数

PHP clearstatcache() 函数

此节有 216 人学习过     参与评论

定义和用法

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

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

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

语法

</>code

  1. clearstatcache()

例子

</>code

  1. <?php
  2. //检查文件大小
  3. echo filesize("test.txt");
  4. $file = fopen("test.txt", "a+");
  5. // 截取文件
  6. ftruncate($file,100);
  7. fclose($file);
  8. //清除缓存并再次检查文件大小
  9. clearstatcache();
  10. echo filesize("test.txt");
  11. ?>

输出:

</>code

  1. 792
  2. 100

如对本文有疑问,请提交到交流论坛,广大热心网友会为你解答!! 点击进入论坛

发表评论 (216人查看0条评论)
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
昵称:
最新评论
------分隔线----------------------------
PHP 教程目录

快速入口

· 365软件
· 杰创官网
· 建站工具
· 网站大全

其它栏目

· 建站教程
· 365学习

业务咨询

· 技术支持
· 服务时间:9:00-18:00
365建站网二维码

Powered by 365建站网 RSS地图 HTML地图

copyright © 2013-2024 版权所有 鄂ICP备17013400号