PHP clearstatcache()関数
❮PHPファイルシステムリファレンス例
ファイルサイズを出力し、ファイルを切り捨て、キャッシュをクリアしてから、ファイルサイズを再度出力します。
<?php
//output 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
定義と使用法
clearstatcache()関数は、ファイルステータスキャッシュをクリアします。
PHPは、パフォーマンスを向上させるために、一部の関数のデータをキャッシュします。スクリプトでファイルを複数回チェックする場合は、正しい結果を得るためにキャッシュを避けたいと思うでしょう。これを行うには、clearstatcache()関数を使用します。
構文
clearstatcache(clear_realpath_cache, filename)
パラメータ値
Parameter | Description |
---|---|
clear_realpath_cache | Optional. Indicates whether to clear the realpath cache or not. Default is FALSE, which indicates not to clear realpath cache |
filename | Optional. Specifies a filename, and clears the realpath and cache for that file only |
ヒントと注意
ヒント:キャッシュしている関数:
- stat()
- lstat()
- ファイルが存在しています()
- is_writable()
- is_readable()
- is_executable()
- is_file()
- is_dir()
- is_link()
- filectime()
- fileatime()
- filemtime()
- fileinode()
- filegroup()
- fileowner()
- ファイルサイズ()
- ファイルの種類()
- fileperms()
技術的な詳細
戻り値: | 何もない |
---|---|
PHPバージョン: | 4.0以降 |
PHP変更ログ: | PHP5.3-2つのオプションパラメータを追加しました:clear_realpath_caheと filename |
❮PHPファイルシステムリファレンス