Learn how to optimize PHP OPcache and realpath_cache_size

Here are two important PHP settings for you to optimize in order to guarantee an optimal speed for hosted websites. Learn how to identify and reconfigure running values for realpath_cache_size and PHP Opcache.

As an IIS systems administrator you want your webapplications to run as fast as possible. PHP sites too. Here are two important PHP settings for you to optimize in order to guarantee an optimal speed for hosted websites.

The first article dives into PHP's realpath_cache_size. This setting is used by PHP to cache the real file system paths of filenames, and this value should be increased on systems where PHP opens many files. But how do you know when you have to increase this value? And how high?

On Saotn.org I run an article how to set a good PHP realpath_cache_size that shows you how to utilize PHP realpath_cache_size() and realpath_cache_get() functions to determine whether you have to increase the realpath_cache_size configuration value, and how high it should be.

Equally important, or perhaps even more important, is tuning PHP's OPcache. OPcache is PHP's opcode mechanism where PHP stores precompiled script byte-code in shared memory. This removes the need  for PHP to load and parse scripts on every request.

The cache size has to be large enough to hold most requested precompiled byte-code, but not too large which might make you webapplication consume huge amounts of memory. The amount of MB is configured through opcache.memory_consumption. As important is the interned strings buffer. String interning is a method of storing only one copy of each distinct string value. One thing that happens a lot with CMS'es nowadays is a lot of the same strings. So let's just save one copy of such a string, you configure this using opcache.interned_strings_buffer

More tips and examples are shared for you in my article how to optimize PHP OPcache configuration.

If you combine these two PHP optimizations, you'll quickly notice your website is much for responsive; requests are faster responded to.