Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I tune the PHP realpath cache?

Tags:

Recent versions of PHP have a cache of filenames for knowing the real path of files, and require_once() and include_once() can take advantage of it.

There's a value you can set in your php.ini to set the size of the cache, but I have no idea how to tell what the size should be. The default value is 16k, but I see no way of telling how much of that cache we're using. The docs are vague:

Determines the size of the realpath cache to be used by PHP. This value should be increased on systems where PHP opens many files, to reflect the quantity of the file operations performed.

Yes, I can jack up the amount of cache allowed, and run tests with ab or some other testing, but I'd like something with a little more introspection than just timing from a distance.

like image 530
Andy Lester Avatar asked Oct 13 '08 14:10

Andy Lester


2 Answers

You've probably already found this, but for those who come across this question, you can use realpath_cache_size() and realpath_cache_get() to figure out how much of the realpath cache is being used on your site and tune the settings accordingly.

like image 183
Noodles Avatar answered Oct 12 '22 12:10

Noodles


Though I can't offer anything specific to your situation, my understanding is that 16k is pretty low for most larger PHP applications (particularly ones that use a framework like the Zend Framework). I'd say at least double the cache size if your application uses lots of includes and see where to go from there. You might also want to increase the TTL as long as your directory structure is pretty consistent.

like image 24
inxilpro Avatar answered Oct 12 '22 12:10

inxilpro