Last active
December 6, 2024 15:27
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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