PHP clearstatcache() 函式
❮ PHP 檔案系統參考示例
輸出檔案大小,截斷檔案,清除快取,然後再次輸出檔案大小
<?php
//輸出檔案大小
echo filesize("test.txt");
echo "<br />";
$file = fopen("test.txt", "a+");
//截斷檔案
ftruncate($file,100);
fclose($file);
//清除快取並再次檢查檔案大小
clearstatcache();
echo filesize("test.txt");
?>
上面程式碼的輸出可能是
792
100
定義和用法
clearstatcache() 函式清除檔案狀態快取。
PHP 會快取某些函式的資料以提高效能。如果在指令碼中多次檢查某個檔案,您可能希望避免快取以獲得正確的結果。為此,請使用 clearstatcache() 函式。
語法
clearstatcache(clear_realpath_cache, filename)
引數值
引數 | 描述 |
---|---|
clear_realpath_cache | 可選。指示是否清除 realpath 快取。預設為 FALSE,表示不清除 realpath 快取 |
filename | 可選。指定一個檔名,並僅清除該檔案的 realpath 和快取 |
提示和註釋
提示:會快取的函式
- 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 版本 | 4.0+ |
PHP 更新日誌 | PHP 5.3 - 添加了兩個可選引數:clear_realpath_cahe 和 filename |
❮ PHP 檔案系統參考