Re: [Q] Does PHP have a negative cache for file stat operations?

From: Date: Fri, 20 Mar 2015 06:13:27 +0000
Subject: Re: [Q] Does PHP have a negative cache for file stat operations?
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-85264@lists.php.net to get a copy of this message
Hi! > We're doing some performance work in WinCache, and we're finding that > some frameworks are...uh...enthusiastically using file_exists(), > is_file() and is_dir() functions on files/directories that don't > exist. Every. Single. Pageload. > > Does the PHP stat cache include negative cache entries? If not, why > not? Negative cache is tricky. Most frequent patterns look like this: 1. if(file_exists("blah")) { do stuff } 2. if(!file_exists("blah")) { throw new Exception("no blah!"); } do stuff 3. if(!file_exists("blah")) { create("blah"); } do stuff Caching negative even short term would subtly break case 3, in that it would force creation of the file every time, thus killing any benefit from any caching (usually file creation is much more expensive process). Long term caching would also be big trouble with case 2. Unless there's a way to reset the cache and the app is very careful to do it - but file can be created by external means and also case 2 would be harder to fix without losing the benefits of caching. So one may ask, why case 1 is not a problem? Usually it's because if the file is there, apps rarely delete them by themselves, or at least adding new files is much more frequent operation than deleting existing ones that are used by the app. -- Stas Malyshev smalyshev@gmail.com

« previous php.internals (#85264) next »