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, 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