TubeSum ← Transcribe a video

Adjust these three critical PHP OPcache settings for maximum performance

0h 06m video Published Apr 3, 2025 Transcribed Aug 3, 2026 T Tideways
Intermediate 5 min read For: PHP developers and system administrators responsible for performance tuning of PHP applications.
AI Trust Score 70/100
⚠️ Average / Some Fluff

"Delivers on the promise with actionable advice and a real case study, though some repetition and filler exist."

AI 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.

[00:03]
OPcache Misconfiguration is Common

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.

[00:18]
Case Study: 20% Performance Loss

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.

[01:04]
Three Critical OPcache Settings

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).

[01:37]
Checking Memory Consumption

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.

[02:23]
Max Accelerated Files Too Small

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.

[03:22]
Understanding Cached Keys and Max Keys

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.

[04:18]
Interned Strings Buffer

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.

[05:18]
Monitoring OPcache in Production

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.

[06:11]
Further Resources

More information is available on the Tight blog at tight.com, which has details on setting correct OPcache values.

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.

Mentioned in this Video

Tutorial Checklist

1 01:37 Check PHP info output under Zen OPcache section for memory statistics (used memory, free memory).
2 02:04 If free memory is near zero, increase opcache.memory_consumption to 192 or 256 MB.
3 03:22 Check cached keys vs max keys; if close, increase opcache.max_accelerated_files (e.g., 10-fold).
4 04:18 Set opcache.interned_strings_buffer to 32 MB (highest possible value).
5 05:18 Monitor OPcache in production using tools like Prometheus or Tightways to alert on low resources.

Study Flashcards (10)

What are the three critical OPcache settings?

easy Click to reveal answer

opcache.memory_consumption, opcache.max_accelerated_files, opcache.interned_strings_buffer

01:04

What is the default value for opcache.memory_consumption?

easy Click to reveal answer

128 MB

01:04

What is the default value for opcache.max_accelerated_files?

easy Click to reveal answer

10,000 files

01:21

What is the default value for opcache.interned_strings_buffer?

easy Click to reveal answer

8 MB

01:21

What statistics indicate that memory consumption needs to be increased?

medium Click to reveal answer

When free memory goes towards zero and used memory goes towards the limit (e.g., 128 MB).

01:37

Why is the default max accelerated files too small for applications like Laravel or Magento?

medium Click to reveal answer

Because they use PHP files for caching, quickly reaching 10,000 files, causing scripts to be recompiled on every request.

02:23

What is the relationship between max accelerated files and cached keys?

hard Click to reveal answer

OPcache translates max accelerated files to the nearest prime number to get max keys; if cached keys approach max keys, increase the setting.

03:22

What are interned strings?

medium Click to reveal answer

Class names, function names, variable names, and literal strings in PHP scripts that can be shared across processes.

04:18

What is the recommended value for interned strings buffer?

easy Click to reveal answer

32 MB (the highest possible value).

05:03

Why should you not rely on command line OPcache statistics for web server configuration?

medium Click to reveal answer

Because command line accesses a different OPcache instance than the web server.

05:18

💡 Key Takeaways

📊

20% Performance Improvement

Demonstrates the tangible impact of correct OPcache configuration.

00:18
🔧

Three Key Settings Identified

Provides a clear checklist for developers to focus on.

01:04
💡

Understanding Cached Keys vs Max Keys

Explains the internal mechanism of OPcache file limits.

03:22
💡

Interned Strings Buffer Importance

Highlights a often overlooked setting that affects memory efficiency.

04:18
🔧

Monitoring Tools

Provides practical solutions for production monitoring.

05:18

[00:03] 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

[00:18] 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

[00:33] 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

[00:48] 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

[01:04] 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

[01:21] 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

[01:37] 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

[01:50] 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

[02:04] 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

[02:23] 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

[02:35] 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

[02:50] 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

[03:06] 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

[03:22] 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

[03:34] 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

[03:48] 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

[04:03] 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

[04:18] 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

[04:34] 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

[04:49] 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

[05:03] and you set should always set it to the highest possible value of 32 megabytes and then you usually don't run into problems

[05:18] 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

[05:34] accesses a different opcache and uh the values from there cannot be com um used the web server so there are a few tools

[05:46] 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

[05:58] 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

[06:11] 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

[06:26] 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

More from Tideways

View all

⚡ Saved you 0h 06m reading this? Transcribe any YouTube video for free — no signup needed.