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

From: Date: Fri, 20 Mar 2015 02:33:12 +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-85261@lists.php.net to get a copy of this message
On 19 March 2015 at 20:26, Eric Stenson <ericsten@microsoft.com> wrote: > PHP Internals folks-- > > 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. What context are these filesystem hits in, is it class autoloading by any chance? If so there was a function added to OPCache and a hopefully upcoming feature to Composer that may be of interest. http://php.net/manual/en/function.opcache-is-script-cached.php https://github.com/composer/composer/pull/3802 Those two combined eliminate a huge number of file_exists calls, similar to what you are describing. Though I guess the is_file and is_dir functions might be in a different area of code. > Does the PHP stat cache include negative cache entries? If not, why not? Negative caches tend to just be the wrong thing. A positive cache returns usable data, with the proviso that the data might be out of date. A negative cache, returns nothing usable. For example, a browser caching a page that returns a 200 response is fine, as it's caching some information that was acceptable. A browser caching a 50x error page would just be caching useless information. Another example - the Composer autoloader behaves as a negative cache, in that it caches the 'fact' that a class doesn't exist. This gets in the way of being able to dynamically generate code, as once you've called class_exists("SomeAutogeneratedClass", true); you can no longer use the registered autoloaders to load that class, and instead have to load it by hand. cheers Dan

« previous php.internals (#85261) next »