Why PHP Can Keep Running Old Code After Deployment

Last updated on August 8th, 2026 at 02:57 pm

If PHP still behaves like the old version after a deployment, check OPcache before changing the code again. The files may be current while PHP-FPM is still running previously compiled bytecode.

What I learned

OPcache improves performance by storing compiled PHP code in memory. In production, opcache.validate_timestamps=0 tells PHP not to check whether source files have changed.

This is efficient for an immutable deployment, but it changes the deployment requirement: updating files alone is not enough. PHP-FPM must reload, restart, or be replaced so the new code is compiled.

Why the symptom is confusing

A deployment may look successful because the new commit is present and part of the application still works. However, a long-running PHP process can continue executing code cached before the deployment.

This creates a misleading split: the source on disk is new, but the running behavior is old.

How to diagnose it

  1. Confirm the expected change exists in the deployed source files.
  2. Check the OPcache setting used by PHP-FPM, especially opcache.validate_timestamps.
  3. Reload or restart PHP-FPM, or recreate the PHP application container.
  4. Repeat the affected action.
  5. Verify the exact output or stored value that should have changed.

Common mistakes

  • Cause: Clearing the framework cache only. Fix: Refresh PHP-FPM or OPcache as part of deployment.
  • Cause: Checking PHP CLI settings instead of the web runtime. Fix: Verify the configuration used by PHP-FPM.
  • Cause: Building a new container image but leaving the old container running. Fix: Confirm the application container was recreated successfully.
  • Cause: Assuming a successful code push means the running process loaded it. Fix: Add a post-deployment behavior check.

Recommended deployment rule

If timestamp validation is disabled, make the PHP process refresh an explicit deployment step. This keeps the performance benefit while preventing stale code from surviving a release.

Conclusion

The concrete takeaway is simple: when PHP files are updated but behavior is unchanged, verify OPcache and restart the correct PHP runtime before debugging the application logic again.

Tags:

Leave a Comment

Discover more from Juzhax Technology

Subscribe now to keep reading and get access to the full archive.

Continue reading