Skip to content

Instantly share code, notes, and snippets.

@neverything
Last active March 6, 2021 12:32
Show Gist options
  • Save neverything/1a0a56a753b795e4f5da to your computer and use it in GitHub Desktop.
Save neverything/1a0a56a753b795e4f5da to your computer and use it in GitHub Desktop.
Dirty opcache_reset() for capistrano deployments to shared php envs without access to restart the server. With some recommended settings for the opcache configuration in php.ini
# In your config/deploy/<stage>.rb files add the correct path which is publicly curlable :D
# Opcache file url
set :opcache_file_url, "https://<add_public_url_of_stage>/opcache_clear.php"
# In your config/deploy.rb file add the following task
namespace :deploy do
desc 'Create a temporary PHP file to clear the opcache.'
task :clear_cache do
on roles(:app) do
within fetch(:release_path) do
opcache_file = "#{fetch(:release_path)}/opcache_clear.php"
execute :touch, "#{opcache_file}"
execute :chmod, "-R 644 #{opcache_file}"
execute :echo, "'<?php opcache_reset(); ?>' > #{opcache_file}"
execute :curl, "-s #{fetch(:opcache_file_url)} && rm -f #{opcache_file}"
end
end
end
end
after 'deploy:finishing', 'deploy:clear_cache'
opcache.enable=1
opcache.validate_timestamps=0
opcache.memory_consumption=128
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=4000
opcache.revalidate_freq=60
# Might be an issue: https://tideways.io/profiler/blog/fine-tune-your-opcache-configuration-to-avoid-caching-suprises
opcache.fast_shutdown=0
opcache.enable_cli=1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment