clearstatcache() 函數清除檔案狀態快取。
PHP 會快取某些函數的回傳訊息,以便提供更高的效能。但是有時候,例如在一個腳本中多次檢查同一個文件,而該文件在此腳本執行期間有被刪除或修改的危險時,你需要清除文件狀態緩存,以便獲得正確的結果。要做到這一點,請使用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//check filesizeecho filesize("test.txt");echo "<br />";$file = fopen("test.txt", "a+");// truncate fileftruncate($file,100) ;fclose($file);//Clear cache and check filesize againclearstatcache();echo filesize("test.txt");?>上面的程式碼將輸出:
792100