首页 > php函数 > php clearstatcache -清除文件状态缓存

php clearstatcache -清除文件状态缓存

关于php clearstatcache -清除文件状态缓存 下面我们一一讲解了,还有具体的实例哦。

关于php clearstatcache -清除文件状态缓存 下面我们一一讲解了,还有具体的实例哦。

clearstatcache ( PHP 4中, PHP 5中) 

clearstatcache -清除文件状态缓存 

描述 

无效clearstatcache ( [布尔$ clear_realpath_cache =虚假[ ,字符串$文件名] ] ) 

当您使用统计() , lstat() ,或任何其他职能中列出的受影响的功能列表中(如下) , PHP的缓存信息恢复这些职能,以提供更快的性能。然而,在某些情况下,您可能要清除缓存信息。例如,如果相同的文件正在检查多次在一个脚本,该文件是危险的删除或更改在该脚本的运行,你可以选择清除缓存的地位。在这种情况下,您可以使用clearstatcache()函数明确的信息, PHP的缓存有关文件。 

你也应该注意到, PHP不缓存信息不存在的文件。因此,如果您要求file_exists()上的文件不存在,它会返回FALSE ,直到您创建文件。如果您创建的文件,它会返回即使您然后删除该文件。然而断开()自动清除缓存。 

注:此功能缓存信息的具体文件名,所以你只需要调用clearstatcache()如果您是从事多种业务在同一文件名,并要求有关该特定文件不被缓存。 

受影响的功能包括统计() , lstat() , file_exists() , is_writable() , is_readable() , is_executable() , is_file() , is_dir() , is_link() , filectime() , fileatime() , filemtime() , fileinode() ,档案群组() , fileowner() ,档案大小() ,文件类型() ,和fileperms() 。 

参数 

clear_realpath_cache 

每当清除缓存或不realpath (默认为false ) 。 

文件名 

明确realpath缓存的具体文件名,如果只使用clear_realpath_cache是真实的。 

返回值 

没有价值的返回。 

修改 

版本说明 

5.3.0时间可选clear_realpath_cache和文件名参数。 

实例 

例如# 1 clearstatcache()的例子

<?php
$file = 'output_log.txt';
function get_owner($file)
{
    $stat = stat($file);
    $user = posix_getpwuid($stat['uid']);
    return $user['name'];
}
$format = "UID @ %s: %sn";
printf($format, date('r'), get_owner($file));
chown($path, 'ross');
printf($format, date('r'), get_owner($file));
clearstatcache();
printf($format, date('r'), get_owner($file));
?>

输出

UID @ Sun, 12 Oct 2008 20:48:28 +0100: root
UID @ Sun, 12 Oct 2008 20:48:28 +0100: root
UID @ Sun, 12 Oct 2008 20:48:28 +0100: ross


教程网址:http://www.phprm.com/function/059f773feafda308082e4e43d4f7a9f8.html

欢迎收藏∩_∩但请保留本文链接。

标签:none

发表留言