Flush PHP OpCache in a multi-replica Docker Swarm or Kubernetes cluster

9/13/2021

I have a Docker Swarm cluster (and a Kubernetes cluster too, in another infrastructure) with a scalable PHP-FPM Docker service, with the Zend OpCache extension installed, and mostly used to serve PHP-based platforms (like WordPress or Drupal).

The issue is this: whenever I use the "flush opcache" functionality of a script or CMS plugin, only the opCache of the currently serving container is actually flushed. If I refresh the page, and this time I happen to load a page being served from the another container/replica, of course I don't see the changes.

Restarting a whole cluster each time a plugin is updated or a theme file is edited is unwieldy and, moreover, probably requires the collaboration of the sysadmin managing the cluster!

Have any of you Swarm/Kubernetes users found any solution? I'm thinking about dropping OpCache altogether!

-- CharlesM
docker-swarm
fpm
kubernetes
opcache
php

0 Answers