set PHP realpath_cache_size ‘correctly’

Back in 2012 I started enabling PHP realpath_cache_size And realpath_cache_ttl for performance gains. At that time, I followed the settings I found Here (since removed). It bothered me that I was blindly determining the size of the cache without actually knowing how much storage was being used. In this post I will show you how to see the size and content of realpath_cache. Thus enabling you to tune the settings based on your usage.

Checking realpath_cache_size usage

As you search the web you will find blog posts asking you to set realpath_cache_size to 128K, 512K and even 1M. These suggestions are made blindly without really knowing how much storage is being used. I thought I’d share Measure With those who stumble upon this post.

Just create a new php file. You can name it anything, (I used: rpc_size.php) then paste the code example listed Here, in that file. Next, upload it to your web server (eg “/var/www/html/”) and then go to And that page will return how much memory the realpath cache is currently using. Like this:


So in my case I am using about 178KB realpath_cache. I had realpath_cache_size set to 4M and so I was able to reduce it to “realpath_cache_size=1M” in php.ini. realpath_cache_size The default x256 was increased from 16K to 4M (4096K).

Note that if you are using Apache Prefork-mpm mod_php to run PHP (only with the fastest and not stable stuff when loading PHP) then realpath_cache_size is used for the launch of each apache2 client. So if you have maxclients set to 50 in your Apache2 config and you spawned 40 clients, a setting of realpath_cache_size = 1M will be applied 40 times! That was advice from 2012, if you’re still using Apache, you should avoid mpm-prefork and use instead mpm_event or even mpm_worker With PHP-FPM. PHP’s default:

realpath_cache_size = 4M
realpath_cache_ttl = 120

PHP Realpath Cache Size

setting realpath_cache_size

My advice, set you new default for PHP 7 of 4M, check the storage using the instructions above and finally reduce the size only if you have less server memory. Also tune realpath_cache_ttl for best performance. Set big again, then tune down by size.

Here my current realpath_cache settings in php.ini are a . is on 3GB StackLinux VPS hosting this blog,

realpath_cache_size = 1M
realpath_cache_ttl = 300

Oh and to see the contents of realpath_cache use:


Check this if you have safe_mode or open_basedir enabled in your php.ini bug (Solutions at the bottom of the page). Basically the realpath cache is not used if safe_mode is on or if the open_basedir restriction is enabled… thus a lot of calls to lstat.


Originally Posted: September 6, 2012 | Last Updated: 21st July 2021

Leave a Comment