當前位置: 首頁> 函數類別大全> clearstatcache

clearstatcache

清除文件狀態緩存
名稱:clearstatcache
分類:文件系統
所屬語言:php
一句話介紹:清除文件狀態緩存。

定義和用法

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()

實例

<?php
//檢查文件大小
echo filesize ( "test.txt" ) ;

$file = fopen ( "test.txt" , "a+" ) ;

// 截取文件
ftruncate ( $file , 100 ) ;
fclose ( $file ) ;

//清除緩存並再次檢查文件大小
clearstatcache ( ) ;
echo filesize ( "test.txt" ) ;
?>

輸出:

 792
100

文法

clearstatcache ( )
同類函數
  • 解析一個配置文件 parse_ini_file

    parse_ini_file

    解析一個配置文件
  • is_writable 的別名 is_writeable

    is_writeable

    is_writable的別名
  • 從文件中格式化輸入 fscanf

    fscanf

    從文件中格式化輸入
  • 返迴路徑中的文件名部分 basename

    basename

    返迴路徑中的文件名部分
  • 從文件指針中讀取一行 fgets

    fgets

    從文件指針中讀取一行
  • 重命名文件或目錄 rename

    rename

    重命名文件或目錄
  • 拷貝文件 copy

    copy

    拷貝文件
  • 返迴路徑中的目錄部分 dirname

    dirname

    返迴路徑中的目錄部分