Search code examples
phpopcache

When exactly does PHP 5.5+ Opcache check file timestamp based on revalidate_freq setting


Apologies of this has been asked before/elsewhere but I cannot find the answer.

We have some issues in the minute following a deploy and we think they are Opcache related. On our live setup we have the following Opcache settings:

opcache.revalidate_freq=60
opcache.validate_timestamps=1

Which of the following does PHP do?

  1. When PHP needs a file, does it at that point check if it has been 60 seconds since it last generated a new cache of the file and if it has been more then generate a new one for this request?

  2. Or does it run on some form of timer (or something else) where the 60 seconds is unrelated to when it last needed the file?

I'd expect option 1 but that wouldn't explain our 60 seconds or so of problems as the file path for the files is different as we deploy to an alternating A or B directory each time.

I hope that makes sense? Thanks for your help.


Solution

  • So, from the PHP manual

    How often to check script timestamps for updates, in seconds. 0 will result in OPcache checking for updates on every request.

    So what's happening is you're updating the file, but your directive says that it's up to 60 seconds between the time you update the file and the time opcache builds a new opcode.

    validate_timestamps has the answer. Because you want to manually revalidate the file you can do this

    When this directive is disabled, you must reset OPcache manually via opcache_reset(), opcache_invalidate() or by restarting the Web server for changes to the filesystem to take effect.