• If you are still using CentOS 7.9, it's time to convert to Alma 8 with the free centos2alma tool by Plesk or Plesk Migrator. Please let us know your experiences or concerns in this thread:
    CentOS2Alma discussion

Issue Opcache keeps restarting itself

xberg

New Pleskian
Hi,

Problem: Opcache keeps restarting itself every 30 seconds or so.
My configuration:
Plesk 12.5
php 7.0.14
Apache / Fast CGI

Default settings for opcache, except the memory moved to 128 MB.
opcache.memory_consumption=128

There is NO memory wasted I never reach max memory.
When opcache restarts it leaves no trace in "last restart time" or other restarts:
last_restart_time never
oom_restarts 0
hash_restarts 0
manual_restarts 0

My opcache_hit_rate rate is excellent (during the course of the 30s)

Of course I would want opcache to NOT restart itself.

thanks
 
Last edited:
Hi,

To find the right configuration you should monitor the output of opcache_get_status(false) which you can use to check for the memory, waste and number of used cache keys:

If cache_full is true and a restart is neither pending nor in progress, that probably means that the waste is not high enough to exceed the max waste percentage.

You can check by comparing current_wasted_percentage with the INI variable opcache.max_wasted_percentage. In this case also the cache hit rate opcache_hit_rate will drop below >=99%.

Solution: Increase opcache.memory_consumption setting.

If cache_full is true and num_cached_keys equals max_cached_keys then you have too many files. When there is not enough waste, no restart will be triggered. As a result there are scripts that don't get cached, even though there might be memory available.

Solution: Increase opcache.max_accelerated_files setting.

If your cache is never full, but you are still seeing a lot of restarts, that can happen when you have too much waste or configured the max waste percentage too low.

Solution: Increase opcache.max_waste_percentage setting.

To look for inefficient restart behavior you can evaluate the oom_restarts (related to opcache.memory_consumption setting) and hash_restarts (related to to opcache.max_accelerated_files). Make sure to check when the last restart happened with last_restart_time statistic.

To find a good value for opcache.max_accelerated_files you can use this Bash one-liner to get the number of PHP files under document root of website.:

$ find "website document root"/ -iname *.php|wc -l

whenever a PHP file is executed (for example through include or require) Opcache checks the last time it was modified on disk. Then it compares this time with the last time it cached the compilation of that script. When the file was modified after being cached, the compile cache for the script will be regenerated.

This validation is not necessary in production, when you know the files never change. To disable timestamp validation add the following line to your php.ini:

opcache.validate_timestamps=0

With this configuration you have to make sure that during a deployment, all the caches get invalidated.

Regards,
 
Back
Top