---
title: 'Adjust these three critical PHP OPcache settings for maximum performance'
source: 'https://youtube.com/watch?v=qvj6TFdgpCU'
video_id: 'qvj6TFdgpCU'
date: 2026-08-03
duration_sec: 394
---

# Adjust these three critical PHP OPcache settings for maximum performance

> Source: [Adjust these three critical PHP OPcache settings for maximum performance](https://youtube.com/watch?v=qvj6TFdgpCU)

## Summary

This video explains the importance of correctly configuring PHP OPcache settings for optimal performance. It highlights three critical settings—memory consumption, max accelerated files, and intern strings buffer—and provides guidance on how to determine the right values using PHP info statistics. A case study shows a 20% performance improvement after proper configuration.

### Key Points

- **OPcache Misconfiguration is Common** [00:03] — 90% of people do not check if their OPcache configuration settings are sized for their application. Enabling OPcache since PHP 5.5 does not mean it is configured correctly.
- **Case Study: 20% Performance Loss** [00:18] — A customer did not size OPcache correctly and lost 20% in performance. After correcting settings, compile times and autoloading times dropped, improving performance from 1.6 seconds to 1.3 seconds in the 95% high.
- **Three Critical OPcache Settings** [01:04] — The three most important settings are: opcache.memory_consumption (default 128 MB), opcache.max_accelerated_files (default 10,000 files), and opcache.interned_strings_buffer (default 8 MB).
- **Checking Memory Consumption** [01:37] — In PHP info output under Zen OPcache section, look at 'used memory' and 'free memory'. If free memory goes towards zero, increase memory. For modern PHP applications, 128 MB may be too small; consider 192 or 256 MB.
- **Max Accelerated Files Too Small** [02:23] — Default of 10,000 files is too small for applications like Shopware, Laravel, Symfony, or Magento 2 because they use PHP files for caching. Once cache files are generated, you quickly reach 10,000 files, causing scripts to be recompiled on every request, leading to performance drops.
- **Understanding Cached Keys and Max Keys** [03:22] — OPcache internally translates max accelerated files to the nearest prime number. For 10,000 files, you get 16,229 keys. If cached keys come close to max keys, increase the value. Increasing this setting 10-fold is fine as memory consumption is the upper bound.
- **Interned Strings Buffer** [04:18] — Interned strings include class names, function names, variable names, and literal strings. If the buffer is too small, every request reallocates memory for strings, which is wasteful. Default 8 MB is too small; set to highest possible value of 32 MB.
- **Monitoring OPcache in Production** [05:18] — Sometimes PHP info output is not easily accessible. Command line OPcache statistics differ from web server. Tools like Prometheus can be used to extract metrics, or use Tightways to aggregate and alert on low memory, cache keys, or interned strings.
- **Further Resources** [06:11] — More information is available on the Tight blog at tight.com, which has details on setting correct OPcache values.

### Conclusion

Properly configuring OPcache settings can yield significant performance improvements. By monitoring and adjusting memory consumption, max accelerated files, and interned strings buffer, you can avoid common pitfalls and ensure your PHP applications run efficiently.

## Transcript

be in the camp of 90% of people that do not check if their opcash uh configuration settings are sized for their application even though opcash is enabled since PHP 5.5 that does not mean
that it's configured correctly you can't just enable it and uh assume that everything is going to be all right take this customer for example they didn't uh this customer for example they didn't uh size up correctly and lost 20% in
performance because of this mistake when they corrected it compile times and autoloading times dropped significantly giving them a 20% Improvement in giving them a 20% Improvement in performance from 1.6 seconds to 1.3
seconds in the 95% high that is really great for just setting a few values different configuration values differently what are the important UPC settings that you need to look into there are three settings that are the
most important ones to configure the first one is called opcash memory first one is called opcash memory consumption its default is 128 mbes then there is opcash Max accelerated files which is uh defaulting to 10,000 files
and third there's opcash intern strings buffer which defaults to 8 MB so what are the right values for these settings you can can check in PHP info output under the Zen opcache section you find a few statistics that give you a lot of
information that you can make the right decision on these settings for the opcache uh memory consumption setting you need to look at consumption setting you need to look at two configuration values used memory and
free memory when the free memory statistic is going towards zero then the used memory is going towards the let's say 128 megabytes and in that case it's an indicator that you need to increase the
the memory for modern PHP applications 128 could be too small it might be necessary to increase it to to increase it to 192 or 256 memory uh for example
Max accelerated files and the default of 10,000 is really too small for applications such as shopware laravel uh Symphony or magenta 2 the
reason for this is that they are using PHP files for caching and once uh a lot of these cache files are generated this means that uh files are generated this means that uh in addition to the um third party
libraries that are loaded through composer you quickly get to 10,000 files and then no additional files will be uh stored into opcache even though the memory consumption might potentially allow it this means that
only um a few scripts are compiled over and over again in every request causing let's say the 20% drop that you saw for this customer before to check if um you are next to this limit you need to look at the two
values cached keys and Max Keys why are they not called cached files and Max files files the reason for this is that uh opcash internally
translates the max accelerated files to the nearest prime number so for the default of 10,000 you get 16,2 29 keys and um these are filled
16,2 29 keys and um these are filled with um uh with PHP files if the cached Keys value comes close to the max keys that means that you're at the maximum and should increase the value I don't see a problem by increasing this
uh configuration setting 10-fold it doesn't have any limitations to do that and the opcash memory consumption is already in Upper Bound for how much uh stuff is going to be stored in opcash the third setting that you need
to look at is the intern strings buffer intern strings are things like class intern strings are things like class names function names variable names and uh literal strings that are inside your PHP scripts all these can be shared uh
in memory and used across all the different parallel processes that run different parallel processes that run PHP for example in Apache or PHP fbm if you don't set this setting high enough then every request needs to
reallocate the same memory for a string that is used across different uh scripts and processes and that is uh very wasteful the default value of 8 megab is really too small for modern applications again
and you set should always set it to the highest possible value of 32 megabytes and then you usually don't run into problems
BS in your production setup sometimes it's not that easy to get at the PHP info output and you really need to look at it from the web uh server side because looking at the zent opcache statistics from the command line uh
accesses a different opcache and uh the values from there cannot be com um used the web server so there are a few tools
available that um allow you to extract this information um into a metrix tool you can build this yourself as promeets for example and uh gather this data in
any kind of metric store that you are already using or you can use uh a tool like tight ways who collects this information across all application servers Aggregates it and alerts on it
uh when for example opcash is running low in memory opcash is running low on cash keys or opcash is running low on intern strings memory you can also read up on this on our blog at tight.com which uh has all
our blog at tight.com which uh has all the information about um setting the correct values for opcache you can find the link by clicking here
