PHP
downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

copy> <chown
Last updated: Fri, 29 Aug 2008

view this page in

clearstatcache

(PHP 4, PHP 5)

clearstatcacheEfface le cache de stat()

Description

void clearstatcache ( void )

L'appel à la fonction stat() ou lstat() est relativement coûteux en terme de temps d'exécution. Pour cela, le résultat du dernier appel à l'une des fonctions de statut, (voir la liste ci-dessous), est sauvegardé pour réutilisation ultérieure. Si vous voulez forcer la vérification du statut d'un fichier, dans le cas où le fichier aurait pu être modifié ou aurait disparu, vous devez utiliser la fonction clearstatcache() afin d'effacer de la mémoire les résultats du dernier appel à la fonction.

Sachez que PHP ne met pas en cache les informations concernant un fichier inexistant. Si vous appelez file_exists() sur un fichier qui n'existe pas, la fonction retournera FALSE jusqu'à ce que vous créiez le fichier. Si vous créez le fichier, la fonction retournera TRUE même si vous effacez le fichier.

Note: Cette fonction met en cache des informations sur les fichiers. Vous n'avez donc besoin d'appeler clearstatcache() que si vous faites des opérations multiples sur le dossier, et que vous voulez avoir une version récente des informations.

Les fonctions affectées sont : stat(), lstat(), file_exists(), is_writable(), is_readable(), is_executable(), is_file(), is_dir(), is_link(), filectime(), fileatime(), filemtime(), fileinode(), filegroup(), fileowner(), filesize(), filetype(), et fileperms().

Valeurs de retour

Aucune valeur n'est retournée.



add a note add a note User Contributed Notes
clearstatcache
BlueCamel
07-Aug-2008 03:58
Regarding the previous user note, the docs say that calling unlink() for a file will clear any stats cache for that file. If you're seeing the described windows behavior it sounds like a possible PHP bug or doc bug.
stangelanda at gmail dot com
24-Jan-2008 09:35
It should be noted that a call to any of those functions will cache all of the file's information, not just the information that is returned.

Obviously it is clear that the following requires you to clear the cache.
<?php
    $size1
= filesize($filename);
   
unlink($filename);   
   
$size2 = filesize($filename);
   
// $size2 still equals $size1, unless you cleared the stat cache in between.
?>

<?php
    $access
= fileatime($filename);
   
unlink($filename);   
   
$size = filesize($filename);
   
// $size will be the filesize before it was unlinked, because the filesize was cached when fileatime was called, even though the two functions wouldn't appear to have anything to do with either other.
?>

Confirmed on a windows system.

copy> <chown
Last updated: Fri, 29 Aug 2008
 
 
show source | credits | sitemap | contact | advertising | mirror sites