|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2009-04-23 15:39 UTC] dlafond at lenouvelliste dot qc dot ca
Description:
------------
When files are saved on AFP or SMB mounted sharing, file_exists() and
clearstatcache() function are not working as expected. No problem when
files are saved on local disk. On AFP or SMB volume, file_exists
continue to return true when the file is deleted outside of PHP.
clearstatcache() function seems to have no effect.
But, if the file is deleted with the unlink() function in php,
file_exists return false.
Reproduce code:
---------------
<?
header("Content-type: text/html");
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Cache-Control: no-store, no-cache,must-revalidate");
header("Cache-Control: post-check=0, pre-check=0",false);
header("Pragma: no-cache");
clearstatcache();
$ttt="/Volumes/testdaniel/ttt.txt";
#exec("touch ".$ttt);
#@unlink($ttt);
if(file_exists($ttt)){
echo "exists";
}else{
echo "not exists";
}
clearstatcache();
?>
Expected result:
----------------
"exists" when file really exists
"not exists" when file doesn't exists
Actual result:
--------------
"exists" even after the file was deleted
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Oct 30 19:00:01 2025 UTC |
A workaround to get rid of this persistent stat cache when using file_exists is to combine the file_exists function with the function realpath(). $ttt="/Volumes/testdaniel/ttt.txt"; if(file_exists(realpath($ttt))){ echo "exists"; }else{ echo "not exists"; }Experiencing the same problem. clearstatcache() does not clear cache for file_exists() and is_file(). Sample code: $path = /images/logo.png; clearstatcache(); if( file_exists($path) ) // also tried file_exists(realpath($path)) $exists = true; else $exists = false; clearstatcache(); echo "file is $path <br>"; echo "file exists is $exists";