PHP clearstatcache() 函數(shù)

2018-11-21 15:58 更新

PHP clearstatcache() 函數(shù)


PHP Filesystem 參考手冊(cè) 完整的 PHP Filesystem 參考手冊(cè)

定義和用法

clearstatcache() 函數(shù)清除文件狀態(tài)緩存。

PHP 會(huì)緩存某些函數(shù)的返回信息,以便提供更高的性能。但是有時(shí)候,比如在一個(gè)腳本中多次檢查同一個(gè)文件,而該文件在此腳本執(zhí)行期間有被刪除或修改的危險(xiǎn)時(shí),你需要清除文件狀態(tài)緩存,以便獲得正確的結(jié)果。要做到這一點(diǎn),請(qǐng)使用 clearstatcache() 函數(shù)。

語(yǔ)法

clearstatcache()


提示和注釋

提示:會(huì)進(jìn)行緩存的函數(shù),即受 clearstatcache() 函數(shù)影響的函數(shù):

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

實(shí)例

<?php
//check filesize
echo filesize("test.txt");
echo "<br />";

$file = fopen("test.txt", "a+");
// truncate file
ftruncate($file,100);
fclose($file);

//Clear cache and check filesize again
clearstatcache();
echo filesize("test.txt");
?>

上面的代碼將輸出:

792
100


PHP Filesystem 參考手冊(cè) 完整的 PHP Filesystem 參考手冊(cè)
以上內(nèi)容是否對(duì)您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號(hào)
微信公眾號(hào)

編程獅公眾號(hào)