diff --git a/ansible/roles/opcache/files/opcache.php b/ansible/roles/opcache/files/opcache.php new file mode 100644 index 0000000..a3109a6 --- /dev/null +++ b/ansible/roles/opcache/files/opcache.php @@ -0,0 +1,278 @@ + 1048576) { + return sprintf("%.2f MB", $bytes/1048576); + } elseif ($bytes > 1024) { + return sprintf("%.2f kB", $bytes/1024); + } else { + return sprintf("%d bytes", $bytes); + } +} + +function getOffsetWhereStringsAreEqual($a, $b) +{ + $i = 0; + while (strlen($a) && strlen($b) && strlen($a) > $i && $a{$i} === $b{$i}) { + $i++; + } + + return $i; +} + +function getSuggestionMessage($property, $value) +{ + switch ($property) { + case 'opcache_enabled': + return $value ? '' : ' You should enabled opcache'; + break; + case 'cache_full': + return $value ? ' You should increase opcache.memory_consumption' : ''; + break; + case 'opcache.validate_timestamps': + return $value ? ' If you are in a production environment you should disabled it' : ''; + break; + } + + return ''; +} + +function getStringFromPropertyAndValue($property, $value) +{ + if ($value === false) { + return 'false'; + } + + if ($value === true) { + return 'true'; + } + + switch ($property) { + case 'used_memory': + case 'free_memory': + case 'wasted_memory': + case 'opcache.memory_consumption': + return size_for_humans($value); + break; + case 'current_wasted_percentage': + case 'opcache_hit_rate': + return number_format($value, 2).'%'; + break; + case 'blacklist_miss_ratio': + return number_format($value, 2); + break; + } + + return $value; +} + +?> + + + + OPcache Dashboard - Carlos Buenosvinos (@buenosvinos) + + + + + + + + + + +Fork me on GitHub + + +
+
+

OPcache Dashboard

+

by Carlos Buenosvinos (@buenosvinos)

+

PHP: and OPcache:

+
+ + +

Hits: %

+
+
+ Hits +
+
+ Misses +
+
+ + + +

Memory: of

+
+
+ Wasted memory +
+
+ Used memory +
+
+ Free memory +
+
+ + +

Keys: of

+
+
+ Used keys +
+
+ Free keys +
+
+ +

Status

+
+ + $value) { + if ($key == 'scripts') { + continue; + } + + if (is_array($value)) { + foreach ($value as $k => $v) { + $v = getStringFromPropertyAndValue($k, $v); + $m = getSuggestionMessage($k, $v); + ?> +
+
+ +

Configuration

+
+ + $value) { + $mess = getSuggestionMessage($key, $value); + ?> + + + + + + +
+
+ +

Scripts () Reset all

+ + + + + + + + $data) { + $offset = min( + getOffsetWhereStringsAreEqual( + (null === $previousKey) ? $key : $previousKey, + $key + ), + (null === $offset) ? strlen($key) : $offset + ); + $previousKey = $key; + } + + foreach ($status['scripts'] as $key => $data) { + ?> + + + + + + + +
OptionsHitsMemoryPath
Invalidate
+
+ + + + + diff --git a/ansible/roles/opcache/tasks/main.yml b/ansible/roles/opcache/tasks/main.yml new file mode 100644 index 0000000..9a8aeb4 --- /dev/null +++ b/ansible/roles/opcache/tasks/main.yml @@ -0,0 +1,47 @@ +--- + +- name: copy opcache script to server + ansible.builtin.copy: + src: opcache.php + dest: /data/services/web/default/opcache.php + owner: www-data + group: www-data + mode: 0644 + +- name: remove opcache tuning in www.conf pool + ansible.builtin.lineinfile: + path: "/etc/php/{{ php_version }}/fpm/pool.d/www.conf" + state: absent + line: "{{ item }}" + with_items: + - "php_value[opcache.max_accelerated_files] = 10000" + - "php_value[opcache.memory_consumption] = 128" + +- name: On sort le serveur du pool + ansible.builtin.file: + path: /data/services/web/default/check/.online + state: absent + +- name: sleep for 6 seconds and continue with play + ansible.builtin.wait_for: timeout=6 + delegate_to: localhost + +- name: restart php-fpm and apache + ansible.builtin.systemd: + name: "{{ item }}" + state: restarted + with_items: + - apache2 + - "{{ 'php' + php_version + '-fpm' }}" + +- name: On remet le serveur dans le pool + ansible.builtin.file: + path: /data/services/web/default/check/.online + state: touch + mode: '0777' + owner: "{{ user }}" + group: "{{ user }}" + +- name: sleep for 3 seconds and continue with play + ansible.builtin.wait_for: timeout=3 + delegate_to: localhost