Skip to content

Cachetool Capistrano plugin? #57

@pmeinhardt

Description

@pmeinhardt

This is not directly related to the capistrano/composer plugin, but I didn't know where to best ask… Here seemed to be a somewhat suitable place since the target audience is likely similar.

Until recently I have never deployed a PHP project, so that was a bit of an adventure ⛵️🙂

However, I needed to clear the OPcache as part of the deployment and this seemed like it would be something that's a common task for PHP deployments. Hence I whipped up a cachetool.rake that obviously uses a lot of code I found here.

https://gist.github.com/pmeinhardt/0a9a72c2f9a07f51304bdb2ed581e52e

It is relatively small and has tasks that mirror all the cachetool commands:

cap cachetool:apc:bin:dump                # Get a binary dump of files and user variables
cap cachetool:apc:bin:load                # Load a binary dump into the APC file and user variables
cap cachetool:apc:cache:clear             # Clears APC cache (user, system or all)
cap cachetool:apc:cache:info              # Shows APC user & system cache information
cap cachetool:apc:cache:info:file         # Shows APC file cache information
cap cachetool:apc:key:delete              # Deletes an APC key
cap cachetool:apc:key:exists              # Checks if an APC key exists
cap cachetool:apc:key:fetch               # Shows the content of an APC key
cap cachetool:apc:key:store               # Store an APC key with given value
cap cachetool:apc:regexp:delete           # Deletes all APC key matching a regexp
cap cachetool:apc:sma:info                # Show APC shared memory allocation information
cap cachetool:apcu:cache:clear            # Clears APCu cache
cap cachetool:apcu:cache:info             # Shows APCu user & system cache information
cap cachetool:apcu:cache:info:keys        # Shows APCu keys cache information
cap cachetool:apcu:key:delete             # Deletes an APCu key
cap cachetool:apcu:key:exists             # Checks if an APCu key exists
cap cachetool:apcu:key:fetch              # Shows the content of an APCu key
cap cachetool:apcu:key:store              # Store an APCu key with given value
cap cachetool:apcu:regexp:delete          # Deletes all APCu key matching a regexp
cap cachetool:apcu:sma:info               # Show APCu shared memory allocation information
cap cachetool:help                        # Displays help for a command
cap cachetool:install_executable          # Installs cachetool.phar to the shared directory
cap cachetool:list                        # Lists commands
cap cachetool:opcache:configuration       # Get configuration information about the cache
cap cachetool:opcache:invalidate:scripts  # Remove scripts from the opcode cache
cap cachetool:opcache:reset               # Resets the contents of the opcode cache
cap cachetool:opcache:status              # Show summary information about the opcode cache
cap cachetool:opcache:status:scripts      # Show scripts in the opcode cache
cap cachetool:self-update                 # [selfupdate] Updates cachetool.phar to the latest version
cap cachetool:stat:clear                  # Clears the file status cache, including the realpath cache
cap cachetool:stat:realpath_get           # Show summary information of realpath cache entries
cap cachetool:stat:realpath_size          # Display size of realpath cache

I use it as follows:

# config/deploy.rb

# Set the cachetool default flags
#
# The deploy user is called `deploy-appname`,
# the socket file however is `appname-fpm.sock`.
set :cachetool_flags, %w[--fcgi="/var/run/php/${USER##deploy-}-fpm.sock"]

# Configure hooks
namespace :deploy do
  # Clear the PHP OPcache
  after :published, 'cachetool:opcache:reset'
end

Not sure whether this would be worth a separate Capistrano gem?

If so, I don't see myself maintaining it since the current PHP project is a bit of a rare bird among my projects so I wouldn't have much use for it.

However, if you're up for it, feel free to use the code from the Gist and do with it what you want 😉

Cheers 👋

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions