Can anyone tell me what exactly is meant by realpath_cache
in PHP? Lots of references have been made to it in the PHP manual, but nothing explains it adequately. For example, the article on clearstatecache
says that the parameter clear_realpath_cache
denotes whether to clear the realpath cache or not. What is meant by this statement?
Asked
Active
Viewed 5,494 times
10

SexyBeast
- 7,913
- 28
- 108
- 196
-
Yeah, that seems to be it indeed, but what is meant by *caching realpath*? – SexyBeast Sep 06 '12 at 13:30
-
2See this thread: http://stackoverflow.com/questions/197734/how-can-i-tune-the-php-realpath-cache for an explanation of what is it and how it can be tuned. – GolezTrol Sep 06 '12 at 13:30
-
Realpath'd values are cached so that they don't have to be looked up, presumably. – Waleed Khan Sep 06 '12 at 13:30
-
2@arxanas A little guessing doesn't make it clearer. Yes, it has something to do with caching and something with paths, but OP would be able to guess that too. – GolezTrol Sep 06 '12 at 13:31
1 Answers
5
realpath_cache
is the system that allows php to cache paths to locations of files/directories you are using to minimize expensive disk lookups. It could possibly greatly improve performance of you PHP application/site if you use alot of relative file paths PHP has to parse/lookup each time you reference them.
-
How can path be cached? Contents of a file can be cached, how can a path be cached? – SexyBeast Sep 06 '12 at 13:31
-
for every include/require statement you do in you app PHP has to figure out where that particular file is, it gets even more complex for PHP when you reference relative paths to your includes. By caching them PHP saves itself some lookups and that might improve performance. It's all php internal stuff though so you really can't "see" much of it unless you gain huge performance improvements out of it. – ChrisR Sep 06 '12 at 13:34
-
1@Cupidvogel read [here](http://uk.php.net/manual/de/function.realpath-cache-get.php) – Mihai Iorga Sep 06 '12 at 13:34
-
File includes can contain just a file name, in which case PHP is find out where the file would be. See the documentation of `include` for info about where it searches. http://www.php.net/manual/en/function.include.php The realpath cache can speed up this search by caching the full paths of files searched before. – GolezTrol Sep 06 '12 at 13:34
-
So when will it come in handy? Files are included or required only once, then and there the contents are merged with the current script. Why should there be any need to access that file again? – SexyBeast Sep 06 '12 at 13:36
-
@Cupidvogel Take frameworks like ZendFramework or large applications like Magento for example. There are numerous files that are autoloaded/included multiple times (Exceptions for example). When you are diving into more complex and large systems it's not that uncommon really. – ChrisR Sep 06 '12 at 13:38
-
The cache lives in the Apache worker (increases its memory footprint) and is used by subsequent PHP processes. It is interesting to see what is inside using realpath_cache_get(). – brablc Aug 16 '13 at 15:28