clearstatcache
(PHP 4, PHP 5, PHP 7, PHP 8)
clearstatcache — Elimina la caché de stat()
Descripción
Tenga en cuenta que PHP no guarda en caché información sobre
un fichero inexistente. Si se llama a file_exists()
sobre un fichero que no existe, la función devolverá false
hasta que se cree el fichero. Si se crea el fichero,
la función devolverá true
incluso si se borra el fichero.
Nota:
Esta función guarda en caché información sobre ficheros.
Por lo tanto, solo es necesario llamar a clearstatcache() si
se realizan múltiples operaciones sobre el directorio, y se desea tener
una versión actualizada de la información.
Las funciones afectadas incluyen :
stat(),
lstat(),
file_exists(),
is_writable(),
is_readable(),
is_executable(),
is_file(),
is_dir(),
is_link(),
filectime(),
fileatime(),
filemtime(),
fileinode(),
filegroup(),
fileowner(),
filesize(),
filetype(), y
fileperms().
Parámetros
clear_realpath_cache
-
Si también debe vaciarse la caché de rutas reales.
filename
-
Limpia la caché de ruta real de un fichero específico.
Solo puede ser utilizado si el argumento
clear_realpath_cache
vale true
.
Valores devueltos
No devuelve ningún valor.
Ejemplos
Ejemplo #1 Ejemplo con clearstatcache()
<?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));
?>
El resultado del ejemplo
sería algo similar a:
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