What will happen if I set higher value for a function in php.ini
, For example set 2GB to opcache.memory_consumption
for a normal e-commerce web application.
opcache.memory_consumption = 2048
Below is my pod resource configuration
resources:
limits:
cpu: "1"
memory: "1Gi"
requests:
cpu: "450m"
memory: "256Mi"
If I set 2GB for OPcache itself. What will happen if it's exceed actual memory limit of the application.
From the PHP manual:
opcache.memory_consumption int
The size of the shared memory storage used by OPcache, in megabytes. The minimum permissible value is "8", which is enforced if a smaller value is set.
OK, so what is the shared memory storage used for, and why might we want more of it? As it happens, Nikita Popov, one of the most important developers of PHP's internals right now, just wrote a blog post about how opcache works. Before going into details of how, he summarises thus:
The primary purposes of opcache is to cache compilation artifacts in shared memory, to avoid the need to recompile PHP scripts on every execution.
So, the memory is used to cache the result of compiling your PHP code to an intermediate representation used internally. The amount of space needed will depend on how much compiled code you're trying to cache at once.
How do we know if it's enough? By running the opcache_get_status() function. If the memory is full, or very nearly full, there's a chance that some of your scripts aren't getting cached because they don't fit in memory. In that case, increasing the configured memory size will improve performance by caching those files.
If the memory already has plenty of space, then increasing the size further won't make any difference, other than preventing the server using that memory for other things.