Reputation: 2568
Doing this:
php -r 'unlink("path"); clearstatcache(); echo file_exists("path");'
Where path is a full absolute path to a file on my linux machine. Command is returning '1
' even though the file is clearly not there. You can run this command a million times, it will always tell you the file is there.
Running:
ls path
Tells you there's no such file.
what gives?
Update: I know about clearstatcache(). That does not help in this case. Additionally, I'm running this with the cli. Nothing changes from run to run. I'm also on a 64-bit VM running ubuntu 11.10.
Path is just a path on the filesystem: /var/www/yo.txt. www is a nfs shared mount, not sure if that has something to do with it. The file was removed from a remote machine, but the local machine seems to know its not there. 'ls' on the directory shows no files, and ls with the path claims says that the file is not there. The file was just a few kb, nothing huge.
Upvotes: 3
Views: 1069
Reputation: 39364
PHP is telling the truth it knows. The culprit is the NFS attribute cache. You can call clearstatcache
all day long, to no effect: NFS is in charge.
I explored what's happening in another SO answer, but the short answer is this: tune your NFS mount options to give you faster answers (try noac
) or use opendir()
and closedir()
to invalidate the NFS cache then call clearstatcache()
, like:
php -r 'unlink("path"); $d = dirname("path"); opendir($d); closedir($d); clearstatcache(); echo file_exists("path");'
Upvotes: 2