re stangelanda at gmail dot com
I have tested this on Windows XP SP3, PHP Version 5.2.5 and I got a warning:
filesize() stat failed for $filename on the second call to the filesize() function
ie it worked as I would expect so unless the bug has been introduced since then - no bug.
clearstatcache
(PHP 4, PHP 5)
clearstatcache — Czyści bufor statusu pliku
Opis
Kiedy używasz stat(), lstat() lub dowolnej z funkcji wymienionej niżej, PHP buforuje informacje, zwrócone przez te funkcje w celu zapewnienia większej wydajności. Jednakże, w kilku przypadkach, możesz chcieć wyczyścić zbuforowane informacje. W przypadku, gdy ten sam plik jest sprawdzany wiele razy w tym samym skrypcie i istnieje obawa, że plik ten zostanie zmieniony lub usunięty podczas pracy skryptu, możesz wywołać czyszczenie bufora stanu. W takim przypadku, możesz użyć funkcji clearstatcache() do wyczyszczenia informacji o pliku zbuforowanej przez PHP.
Weź pod uwagę, że PHP nie buforuje informacji o nie istniejących plikach. Jeśli wywołasz file_exists() na pliku, który nie istnieje zostanie zwrócone FALSE dopóki nie stworzysz tego pliku. Jeśli go utworzysz funkcja zwróci TRUE nawet jeśli go później skasujesz. unlink() czyści automatycznie bufor.
Informacja: Ta funkcja buforuje informacje o podanych nazwach plików, więc potrzebujesz wywoływać clearstatcache() jeśli wykonujesz wiele operacji na tym samym pliku i potrzebujesz aby informacje o tym pliku nie były buforowane.
Dotyczy funkcji stat(), lstat(), file_exists(), is_writable(), is_readable(), is_executable(), is_file(), is_dir(), is_link(), filectime(), fileatime(), filemtime(), fileinode(), filegroup(), fileowner(), filesize(), filetype() i fileperms().
Zwracane wartości
żadna wartość nie jest zwracana.
clearstatcache
26-Sep-2008 05:49
06-Aug-2008 06: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.
24-Jan-2008 12: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.
