The PHP directive realpath_cache_size sets the size of the realpath cache to be used by PHP. Increasing realpath_cache_size might greatly improve PHP performance, as PHP states: "This value should be increased on systems where PHP opens many files.". Therefore, setting a correct value for PHP realpath_cache_size can greatly improve PHP performance and optimize WordPress - and other CMS's - websites.

All kudos for this goes to Hayden James, who posted this back in november 2011.

PHP realpath_cache_size: tune PHP caching of file path locations

The other day I was looking to even further optimize PHP performance on our Windows Server IIS web servers. While going through my php.ini file, I couldn't find a setting in need of optimization. Even realpath_cache_size was increased to 128k (defaults to 16k), but somehow it caught my eye.

While doing a normal Google search, I stumbled upon the earlier mentioned blog post by Hayden James, and that made me testing with the following:

dump realpath_cache_size result

<?php
	var_dump( realpath_cache_size() );
?>

This will dump the realpath_cache_size() usage, e.g how many kB's are currently in use.

dump realpath_cache_get result - e.g the cached files and locations:

<?php
	var_dump( realpath_cache_get() );
?>

This dumps the cached files and locations.

On our IIS web servers, customers can run any CMS they want. For a regular Drupal, Joomla and WordPress CMS or blog, the 128k for realpath_cache_size is more than enough.

However, Magento requires realpath_cache_size to be set much higher, and Prestashop does too.

For Magento and PrestaShop, set its value around 130 - 150 kB, because they open lots of files. This made me increase the value for PHP's realpath_cache_size setting to tune PHP performance of Magento- and Prestashop webshops on Windows Server IIS web servers.

PHP's realpath_cache_size default size was "16k" prior to PHP 7.0.16 and 7.1.2. Now it defaults to 4M. And, don't forget to optimize your PHP opcache configuration!

About PHP's realpath_cache_size:

The realpath_cache_size size represents the total number of bytes in the path strings stored, plus the size of the data associated with the cache entry. This means that in order to store longer paths in the cache, the cache size must be larger. This value does not directly control the number of distinct paths that can be cached.

https://www.php.net/manual/en/ini.core.php#ini.realpath-cache-size
Donate a cup of coffee
Donate a cup of coffee

Thank you very much! <3 ❤️

1 Comment

  1. I use
    realpath_cache_size = 9096k
    realpath_cache_ttl = 3600

    In a rpc_size.php with var_dump(realpath_cache_size());
    I get every page refresh these value:
    realpath_cache_size= int(904)
    realpath_cache_size= int(578647)
    realpath_cache_size= int(370970)
    realpath_cache_size= int(904)
    realpath_cache_size= int(904)
    realpath_cache_size= int(151356)
    realpath_cache_size= int(578647)
    realpath_cache_size= int(378102)
    realpath_cache_size= int(54050)
    realpath_cache_size= int(6745)
    realpath_cache_size= int(1159)
    I refreshed the page every 1-3 seconds.
    Any ideas why are these fluctuations?

    Another thing : this realpath_cache_size is used by php per site or global (per server)?

    I’m using php 7.4+nginx; drupal 8+9

Comments are closed