For sites that have PHP OPCache enabled:

  1. Does updating site using Drush require restarting the webserver to invalidate the scripts cached by OPCache?
  2. Does Drupal core or Drush invalidate OPCache before running updates?
  3. Is setting opcache.enable_cli to 0 a better strategy in this scenario?
  • 1
    I don't know the answer specifically, but I know that when I have opcache enabled, I don't have to do anything special to flush classes after doing updates or clearing the registry. However, I've never actually confirmed that this is because nothing needs to be done, or because I haven't properly configured opcache. – Jaypan Feb 19 at 21:26
  • This probably can easily be found out in a reproducible Docker setup. – leymannx Feb 20 at 13:51
  1. Restarting the webserver works, but takes quite some time. A more efficient solution is to have a way to call opcache_reset.
  2. Opcache must be reset by calling opcache_reset from within the web process. If you call it inside drush then it will not clear the opcache for the webserver so it won't help the problem.
  3. Unless you are really explicit in your configuration of opcache to enable it on the cli and also use a file based caching mechanism, the opcache exists in memory and is reset on each command line invocation. Therefore you only need to worry about clearing opcache by restarting any long-running PHP command line jobs.

If you want to clear opcache as part of a deploy process, I suggest adding a file that contains opcache_reset and then you have to protect access to that file so malicious users can't easily call it:

  1. Give it a long random string as a name (like 100+ characters).
  2. Check the IP address of the requester it can only be called from trusted networks.
  • thanks for sharing the information. Yes, pretty clear that the opcache_reset needs to be performed from the web. However, my question is pertaining to drush? From experience it appears drush may be performing a cli-opcache flush when running updatedb command, but I have not looked at the drush code yet. – amit Feb 20 at 20:08
  • I updated my answer item 3 to cover opcache cli behavior a bit more. Drush does not perform any opcache flush by default and it's generally not needed due to the way opcache works for cli. – greggles Feb 22 at 15:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.