php’s OPcache can get saturated

This entry is part 6 of 6 in the series php features

php offers OPcache, an opcode cache. This cache is used to store the results of parsing php code, and its purpose is to speed up server operations by avoiding the overhead reparsing the code for every web or command line request. The OPcache is located in RAM shared by all php processes in a process pool.

It caches two types of data: php opcodes and text strings. The sizes of those buffers are controlled by two php.ini directives, opcache.memory_consumption and opcache.interned_strings_buffer.

Like most long-lived useful software, WordPress grows with each new release. Lately I have noticed that OPcache’s two buffers have been running at 100% full on various sites.

Increasing the sizes of those buffers has improved performance for me. I suggest using these directives in php.ini. On shared hosting, it is necessary to request these changes from your hosting provider.

opcache.memory_consumption=256
opcache.interned_strings_buffer=24

The defaults, as of php version 8.5, are these.

opcache.memory_consumption=128
opcache.interned_strings_buffer=8

php features

php composer, WordPress, and plugins

Leave a Comment