首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

clearstatcache

(PHP 4, PHP 5, PHP 7)

clearstatcache - 清除文件状态缓存

Description

代码语言:javascript
复制
void clearstatcache ([ bool $clear_realpath_cache = false [, string $filename ]] )

当您使用stat(),lstat()或受影响的函数列表(下面)中列出的任何其他函数时,PHP会缓存这些函数返回的信息以提供更快的性能。但是,在某些情况下,您可能需要清除缓存的信息。例如,如果同一文件在单个脚本中被多次检查,并且该脚本有可能在脚本操作期间被删除或更改,则可以选择清除状态缓存。在这些情况下,您可以使用clearstatcache()函数清除PHP缓存文件的信息。

你还应该注意到PHP不会缓存关于不存在的文件的信息。因此,如果您在不存在的文件上调用file_exists(),它将FALSE一直返回,直到您创建该文件。如果您创建该文件,TRUE即使您删除了该文件,该文件也会返回。但unlink()会自动清除缓存。

注意:此函数缓存有关特定文件名的信息,因此如果您对相同的文件名执行多个操作并且要求不缓存关于该特定文件的信息,则只需调用clearstatcache()

受影响的函数包括stat(), lstat(), file_exists(), is_writable(), is_readable(), is_executable(), is_file(), is_dir(), is_link(), filectime(), fileatime(), filemtime(), fileinode(), filegroup(), fileowner(), filesize(), filetype(), and fileperms().

Parameters

clear_realpath_cache

是否清除实时路径缓存。

filename

只清除特定文件名的实际路径和统计缓存; 仅在使用时clear_realpath_cacheTRUE

Return Values

没有值返回。

Changelog

描述

5.3.0

增加了可选的clear_realpath_cache和文件名参数。

Examples

Example #1 clearstatcache() example

代码语言:javascript
复制
<?php
$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));
?>

上面的例子会输出类似于:

代码语言:javascript
复制
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

← chown

copy →

代码语言:txt
复制
 © 1997–2017 The PHP Documentation Group

根据知识共享署名许可证v3.0或更高版本授权。

扫码关注腾讯云开发者

领取腾讯云代金券