I started using the built-in PHP OPcache of PHP 5.6 and am facing a problem now. I set it up to use up to 1 GB of RAM, which is highly enough for my websites but it never get get it to use the full 1 GB of RAM. The cache is cleared many times before it would allocate this limit as you can see on this munin graph:

enter image description here enter image description here

So every few days it deletes all files from the cache and starts again to cache them.

First I thought that the problem is the variable opcache.max_wasted_percentage but it doesn’t care to which value I set it. My configuration is the following:

; configuration for php ZendOpcache module
; priority=05
opcache.enable = 1
opcache.enable_cli = 1
opcache.memory_consumption = 1024
opcache.interned_strings_buffer = 128
opcache.blacklist_filename = /etc/php5/opcache_blacklist.txt
opcache.max_accelerated_files = 65407
opcache.revalidate_freq = 5
opcache.fast_shutdown = 1
opcache.max_wasted_percentage = 50
opcache.enable_file_override = 1

I’m using it in an environment of the latest Debian Jessie with nginx and FastCGI.

I want to achieve that the cache only gets cleared when the memory consumption has reached the 1 GB. I already tried a very minimal configuration looking like this:

; configuration for php ZendOpcache module
; priority=05
opcache.enable = 1
opcache.enable_cli = 1
opcache.memory_consumption = 1024

Even then the problem still persists.

If the FPM config is needed:

user = www
group = www
listen =
listen.owner = www
listen.group = www

listen.allowed_clients =
pm = ondemand
pm.max_children = 100
pm.process_idle_timeout = 5s;


engine = On
short_open_tag = Off
asp_tags = Off
precision = 14
y2k_compliance = On
output_buffering = 4096
zlib.output_compression = Off
implicit_flush = Off
unserialize_callback_func =
serialize_precision = 17
allow_call_time_pass_reference = Off
safe_mode = Off
safe_mode_gid = Off
safe_mode_include_dir =
safe_mode_exec_dir =
safe_mode_allowed_env_vars = PHP_
safe_mode_protected_env_vars = LD_LIBRARY_PATH
disable_functions = escapeshellcmd, exec, ini_restore, passthru, popen, proc_nice, proc_open, shell_exec, show_source, system
disable_classes =
zend.enable_gc = On
expose_php = Off
max_execution_time = 120
max_input_time = 300
memory_limit = 512M
error_reporting = E_ALL & ~E_DEPRECATED
display_errors = Off
display_startup_errors = Off
log_errors = On
log_errors_max_len = 1024
ignore_repeated_errors = Off
ignore_repeated_source = Off
report_memleaks = On
track_errors = Off
html_errors = Off
error_log = /var/log/nginx/php_error.log
variables_order = "GPCS"
request_order = "GP"
register_globals = Off
register_long_arrays = Off
register_argc_argv = Off
auto_globals_jit = On
post_max_size = 2000M
magic_quotes_gpc = Off
magic_quotes_runtime = Off
magic_quotes_sybase = Off
auto_prepend_file =
auto_append_file =
default_mimetype = "text/html"
doc_root =
user_dir =
enable_dl = Off
cgi.fix_pathinfo = 0
file_uploads = On
upload_max_filesize = 200M
max_file_uploads = 200
allow_url_fopen = On
allow_url_include = Off
default_socket_timeout = 60

Hopefully I can found here anyone who already faced this problem and could solve it. So my final question is: How can I configure the OpCache so that it just gets cleared when the usable memory is full?

2 Answers 2


OPcache dumps the entire cache and starts over whenever it hits any of its configured limits. This behavior is a bit annoying, but it's what we're stuck with for now.

Since you aren't hitting the memory limit, my guess is that you're hitting a limit you aren't collecting metrics on.

In particular, you aren't collecting metrics on the number of cache keys (files) in use. I suspect you are hitting the limit of 65407 which you have configured, and should raise it.

Whether you are hitting that limit or not, you should begin gathering this data.

  • Unfortunately I cannot agree with hitting any limit. Currently there is a maximum of 10.000 files cached as you can see in the following graph: Munin Graph The current opcache.max_wasted_percentage is 50 because it's the highest usable value.
    – KittMedia
    Nov 25, 2015 at 8:12
  • Please don't waste our time. If you had this information, you should have posted it originally (and you should do so now). Nov 25, 2015 at 10:40
  • 1
    This is just a small detail, which I didn't know until the last days. There is no documentation about it at PHP itself. Additionally it has no directly connection to my problem because it doesn't rely on this setting. However I edited my question.
    – KittMedia
    Nov 25, 2015 at 12:59

I could now verify what the problem was in my case:

I use a software, which is able to delete its own caches and which uses a package system, where you can install new packages.

Whenever I install a new package or clear the cache, the software runs a opcache_reset() instead of just using opcache_invalidate() because it knows which files are about to be changed…

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .