note 116554 added to function.clearstatcache
| From: | bj at wjblack dot com | Date: | Thu, 22 Jan 2015 02:36:52 +0000 |
| Subject: | note 116554 added to function.clearstatcache | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-201491@lists.php.net to get a copy of this message | ||
Just to make this more obvious (and so search engines find this easier):
If you do fileops of any kind outside of PHP (say via a system() call), you probably want to clear
the stat cache before doing any further tests on the file/dir/whatever. For example:
<?php
// is_dir() forces a stat call, so the cache is populated
if( is_dir($foo) ) {
system("rm -rf " . escapeshellarg($foo));
if( is_dir($foo) ) {
// ...will still be true, even if the rm succeeded, because it's just
// reading from cache, not re-running the stat()
}
}
?>
Pop a clearstatcache() after the system call and all is good (modulo a bit of a performance hit from
having a cleared stat cache :-( ).
----
Server IP: 72.52.91.14
Probable Submitter: 64.235.144.239
----
Manual Page -- http://php.net/manual/en/function.clearstatcache.php
Edit -- https://master.php.net/note/edit/116554
Del: integrated -- https://master.php.net/note/delete/116554/integrated
Del: useless -- https://master.php.net/note/delete/116554/useless
Del: bad code -- https://master.php.net/note/delete/116554/bad+code
Del: spam -- https://master.php.net/note/delete/116554/spam
Del: non-english -- https://master.php.net/note/delete/116554/non-english
Del: in docs -- https://master.php.net/note/delete/116554/in+docs
Del: other reasons-- https://master.php.net/note/delete/116554
Reject -- https://master.php.net/note/reject/116554
Search -- https://master.php.net/manage/user-notes.php