Skip to content
This repository has been archived by the owner on Jun 13, 2019. It is now read-only.

Commit

Permalink
Merge pull request #698 from till/f/opcode-caching
Browse files Browse the repository at this point in the history
F/opcode caching
  • Loading branch information
gilleyj committed Aug 18, 2015
2 parents 365d107 + eb61191 commit f14e16f
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 6 deletions.
4 changes: 1 addition & 3 deletions easybib/recipes/role-phpapp.rb
Expand Up @@ -16,6 +16,4 @@

include_recipe 'tideways'

if is_aws
include_recipe 'php-opcache::configure'
end
include_recipe 'php-opcache::configure'
5 changes: 4 additions & 1 deletion php-fpm/attributes/default.rb
Expand Up @@ -4,8 +4,11 @@

default['php-fpm']['logfile'] = '/var/log/php/error.log'
default['php-fpm']['slowlog'] = '/var/log/php/slow.log'
default['php-fpm']['fpmlog'] = '/var/log/php/fpm.log'
default['php-fpm']['slowlog_timeout'] = 4

default['php-fpm']['fpmlog'] = '/var/log/php/fpm.log'
default['php-fpm']['fpmlog_level'] = 'notice'

default['php-fpm']['displayerrors'] = false
default['php-fpm']['logerrors'] = true
default['php-fpm']['maxexecutiontime'] = 60
Expand Down
1 change: 1 addition & 0 deletions php-fpm/recipes/prepare.rb
Expand Up @@ -57,6 +57,7 @@
mode '0755'
owner node['php-fpm']['user']
group node['php-fpm']['group']
not_if node['php-fpm']['fpmlog'] == 'syslog'
end

directory node['php-fpm']['socketdir'] do
Expand Down
2 changes: 1 addition & 1 deletion php-fpm/templates/default/php-fpm.conf.erb
@@ -1,7 +1,7 @@
[global]
pid = <%= node["php-fpm"]["prefix"] %>/var/run/php-fpm.pid
error_log = <%= node["php-fpm"]["fpmlog"] %>
log_level = notice
log_level = <%= node["php-fpm"]["fpmlog_level"] %>

; If this number of child processes exit with SIGSEGV or SIGBUS within the time
; interval set by emergency_restart_interval then FPM will restart. A value
Expand Down
2 changes: 2 additions & 0 deletions php-fpm/templates/default/pool.conf.erb
Expand Up @@ -25,3 +25,5 @@ ping.response = p0ng
request_slowlog_timeout = <%= @slowlog_timeout %>

slowlog = <%= @slowlog %>

catch_workers_output=1
30 changes: 30 additions & 0 deletions php-opcache/README.md
Expand Up @@ -2,3 +2,33 @@

* `php-opcache::default`: installs the opcache extension
* `php-opcache::configure`: configures the extension for php

## Configuration

Configuration mostly refers to attributes in this cookbook.

Whatever is in `node['php-opcache']['settings']` equals to the available settings
for the OPcache extension and can be changed/extended/etc..

More info: http://docs.php.net/manual/en/opcache.configuration.php

We do not track/list all of them there. Whatever is not "added" falls by back
to the default.

## Operation

1. calculate the number of scripts to cache
* rough number of files in your code-base * 3 (or 4)
* in `opcache_get_status()` look for `max_cached_keys`
* configuration: `max_accelerated_files`
* monitor:
* `hash_restarts` (triggered when this number is exceeded)
* ideally `num_cached_scripts` and `num_cached_keys` are pretty much equal
* e.g. `composer dump-autoload --optimize` helps
2. memory you can spare, or how big is your code base:
* in `opcache_get_status()` look for `used_memory` and `free_memory`
* configuration: `memory_consumption`
* monitor: `oom_restarts`
3. by default `validate_timestamps` is off
* this is not helpful for development environments
* for production priming, check out: https://github.com/easybiblabs/opcache-primer
2 changes: 1 addition & 1 deletion php-opcache/attributes/default.rb
Expand Up @@ -2,7 +2,7 @@
default['php-opcache']['settings'] = {
'memory_consumption' => 500,
'interned_strings_buffer' => 8,
'max_accelerated_files' => 100_000,
'max_accelerated_files' => 12_000,
'validate_timestamps' => 0,
'save_comments' => 1,
'fast_shutdown' => 1,
Expand Down
9 changes: 9 additions & 0 deletions php-opcache/recipes/configure.rb
Expand Up @@ -3,3 +3,12 @@
config_directives node['php-opcache']['settings']
action :setup
end

file 'create opcache error_log' do
path node['php-opcache']['settings']['error_log']
mode 0755
owner node['php-fpm']['user']
group node['php-fpm']['group']
notifies :restart, 'service[php-fpm]', :delayed
only_if node['php-opcache']['settings'].attribute?('error_log')
end

0 comments on commit f14e16f

Please sign in to comment.