Quantcast
Viewing all articles
Browse latest Browse all 69

PHP’s OPCache and Symlink-based Deploys

The post PHP’s OPCache and Symlink-based Deploys appeared first on ma.ttias.be.

In PHP =< 5.4, there was APC. And in APC, there was the apc.stat option to check the timestamps on files to determine if they've changed, and a new version should be cached. However, in PHP 5.5+, it introduces OPCode Caching as an alternative to APC, and that works a bit differently.

Now, with PHP 5.5 and the new OPcache things are a bit different. OPcache is not inode-based so we can't use the same trick [symlink-changes for deploys].
Rasmus Lerdorf

In short: if your PHP code is in the following directory structure, and the current symlink is changed to point to a new release, the OPCache won't read the new file since the path of the file remains the same.

$ ls
current -> releases/20141217084854
releases/20141217084854
releases/20141217085023

If the current symlink changes from releases/20141217084854 to releases/20141217085023, you need to manually clear the OPCache to have it load the new PHP files.

There is no mechanisme (yet?) in OPCache that allows you to stat the source files and check for changes. There are options like opcache.validate_timestamps and opcache.revalidate_freq that allow you to periodically check for changes, but that's always time-based.

So to clear the OPCache after each deploy, you now have two options:

  1. Restart the PHP-FPM daemon (you'll need sudo-rights for this)
  2. Use a tool like cachetool to flush the OPCache via the CLI

This is something to keep in mind.

The post PHP’s OPCache and Symlink-based Deploys appeared first on ma.ttias.be.


Viewing all articles
Browse latest Browse all 69

Trending Articles