首页 > 应用开发 > IT综合 > PHP clearstatcache 文件系统函数
| PHP4 | PHP5 | PHP7 |
|---|---|---|
| 支持 | 支持 | 支持 |
5.3.0 增加了可选的 clear_realpath_cache 和 filename 参数.
clearstatcache ([ bool $clear_realpath_cache = false [, string $filename ]] )
当使用 stat() , lstat() 或者任何列在受影响函数表(见下面)中的函数时,PHP 将缓存这些函数的返回信息以提供更快的性能。然而在某些情况下,你可能想清除被缓存的信息。例如如果在一个脚本中多次检查同一个文件,而该文件在此脚本执行期间有被删除或修改的危险时,你需要清除文件状态缓存。这种情况下,可以用 clearstatcache() 函数来清除被 PHP 缓存的该文件信息。 必须注意的是,对于不存在的文件,PHP 并不会缓存其信息。所以如果调用 file_exists() 来检查不存在的文件,在该文件没有被创建之前,它都会返回 FALSE。如果该文件被创建了,就算以后被删除,它都会返回 TRUE 函数 unlink() 会自动清除该缓存.
| 参数 | 必需的 | 描述 |
|---|---|---|
| clear_realpath_cache | 否 | 是否清除真实路径缓存 |
| filename | 否 | 清除文件名指定的文件的真实路径缓存; 只在 clear_realpath_cache 为 TRUE 时启用 |
$file = 'output_log.txt';
function get_owner($file){
$stat = stat($file);
$user = posix_getpwuid($stat['uid']);
return $user['name'];
}
$format = "UID @ %s: %s\n";
printf($format, date('r'), get_owner($file));
chown($file, 'ross');
printf($format, date('r'), get_owner($file));
clearstatcache();
printf($format, date('r'), get_owner($file));
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/69942367/viewspace-2663614/ ,如需转载,请注明出处,否则将追究法律责任。