Skip to content

Commit e72a9e9

Browse files
committed
Added custom opcache config override
Signed-off-by: Jonathan Rousseau <[email protected]>
1 parent 65138b6 commit e72a9e9

File tree

3 files changed

+37
-14
lines changed

3 files changed

+37
-14
lines changed

Dockerfile-alpine.template

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -88,15 +88,22 @@ RUN set -ex; \
8888
# see https://docs.nextcloud.com/server/latest/admin_manual/installation/server_tuning.html#enable-php-opcache
8989
ENV PHP_MEMORY_LIMIT 512M
9090
ENV PHP_UPLOAD_LIMIT 512M
91+
ENV PHP_OPCACHE_INTERNED_STRINGS_BUFFER 32
92+
ENV PHP_OPCACHE_MAX_ACCELERATED_FILES 10000
93+
ENV PHP_OPCACHE_MEMORY_CONSUMPTION 128
94+
ENV PHP_OPCACHE_SAVE_COMMENTS 1
95+
ENV PHP_OPCACHE_REVALIDATE_FREQ 60
96+
ENV PHP_OPCACHE_JIT 1255
97+
ENV PHP_OPCACHE_JIT_BUFFER_SIZE 128M
9198
RUN { \
9299
echo 'opcache.enable=1'; \
93-
echo 'opcache.interned_strings_buffer=32'; \
94-
echo 'opcache.max_accelerated_files=10000'; \
95-
echo 'opcache.memory_consumption=128'; \
96-
echo 'opcache.save_comments=1'; \
97-
echo 'opcache.revalidate_freq=60'; \
98-
echo 'opcache.jit=1255'; \
99-
echo 'opcache.jit_buffer_size=128M'; \
100+
echo 'opcache.interned_strings_buffer=${PHP_OPCACHE_INTERNED_STRINGS_BUFFER}'; \
101+
echo 'opcache.max_accelerated_files=${PHP_OPCACHE_MAX_ACCELERATED_FILES}'; \
102+
echo 'opcache.memory_consumption=${PHP_OPCACHE_MEMORY_CONSUMPTION}'; \
103+
echo 'opcache.save_comments=${PHP_OPCACHE_SAVE_COMMENTS}'; \
104+
echo 'opcache.revalidate_freq=${PHP_OPCACHE_REVALIDATE_FREQ}'; \
105+
echo 'opcache.jit=${PHP_OPCACHE_JIT}'; \
106+
echo 'opcache.jit_buffer_size=${PHP_OPCACHE_JIT_BUFFER_SIZE}'; \
100107
} > "${PHP_INI_DIR}/conf.d/opcache-recommended.ini"; \
101108
\
102109
echo 'apc.enable_cli=1' >> "${PHP_INI_DIR}/conf.d/docker-php-ext-apcu.ini"; \

Dockerfile-debian.template

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@ RUN set -ex; \
2020
# see https://docs.nextcloud.com/server/stable/admin_manual/installation/source_installation.html
2121
ENV PHP_MEMORY_LIMIT 512M
2222
ENV PHP_UPLOAD_LIMIT 512M
23+
ENV PHP_OPCACHE_INTERNED_STRINGS_BUFFER 32
24+
ENV PHP_OPCACHE_MAX_ACCELERATED_FILES 10000
25+
ENV PHP_OPCACHE_MEMORY_CONSUMPTION 128
26+
ENV PHP_OPCACHE_SAVE_COMMENTS 1
27+
ENV PHP_OPCACHE_REVALIDATE_FREQ 60
28+
ENV PHP_OPCACHE_JIT 1255
29+
ENV PHP_OPCACHE_JIT_BUFFER_SIZE 128M
2330
RUN set -ex; \
2431
\
2532
savedAptMark="$(apt-mark showmanual)"; \
@@ -95,13 +102,13 @@ RUN set -ex; \
95102
# see https://docs.nextcloud.com/server/latest/admin_manual/installation/server_tuning.html#enable-php-opcache
96103
RUN { \
97104
echo 'opcache.enable=1'; \
98-
echo 'opcache.interned_strings_buffer=32'; \
99-
echo 'opcache.max_accelerated_files=10000'; \
100-
echo 'opcache.memory_consumption=128'; \
101-
echo 'opcache.save_comments=1'; \
102-
echo 'opcache.revalidate_freq=60'; \
103-
echo 'opcache.jit=1255'; \
104-
echo 'opcache.jit_buffer_size=128M'; \
105+
echo 'opcache.interned_strings_buffer=${PHP_OPCACHE_INTERNED_STRINGS_BUFFER}'; \
106+
echo 'opcache.max_accelerated_files=${PHP_OPCACHE_MAX_ACCELERATED_FILES}'; \
107+
echo 'opcache.memory_consumption=${PHP_OPCACHE_MEMORY_CONSUMPTION}'; \
108+
echo 'opcache.save_comments=${PHP_OPCACHE_SAVE_COMMENTS}'; \
109+
echo 'opcache.revalidate_freq=${PHP_OPCACHE_REVALIDATE_FREQ}'; \
110+
echo 'opcache.jit=${PHP_OPCACHE_JIT}'; \
111+
echo 'opcache.jit_buffer_size=${PHP_OPCACHE_JIT_BUFFER_SIZE}'; \
105112
} > "${PHP_INI_DIR}/conf.d/opcache-recommended.ini"; \
106113
\
107114
echo 'apc.enable_cli=1' >> "${PHP_INI_DIR}/conf.d/docker-php-ext-apcu.ini"; \

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,15 @@ To customize Apache max file upload limit you can change the following variable:
217217
- `APACHE_BODY_LIMIT` (default `1073741824` [1GiB]) This restricts the total
218218
size of the HTTP request body sent from the client. It specifies the number of _bytes_ that are allowed in a request body. A value of **0** means **unlimited**. Check the [Nextcloud documentation](https://docs.nextcloud.com/server/latest/admin_manual/configuration_files/big_file_upload_configuration.html#apache) for more information.
219219

220+
To customize OPcache parameters you can change the following variables:
221+
- `PHP_OPCACHE_INTERNED_STRINGS_BUFFER` (default `32`) The amount of memory used to store interned strings, in megabytes.
222+
- `PHP_OPCACHE_MAX_ACCELERATED_FILES` (default `10000`) The maximum number of keys (and therefore scripts) in the OPcache hash table. The actual value used will be the first number in the set of prime numbers { 223, 463, 983, 1979, 3907, 7963, 16229, 32531, 65407, 130987, 262237, 524521, 1048793 } that is greater than or equal to the configured value. The minimum value is 200. The maximum value is 1000000. Values outside of this range are clamped to the permissible range.
223+
- `PHP_OPCACHE_MEMORY_CONSUMPTION` (default `128`) The size of the shared memory storage used by OPcache, in megabytes. The minimum permissible value is "8", which is enforced if a smaller value is set.
224+
- `PHP_OPCACHE_SAVE_COMMENT` (default `1`) If disabled, all documentation comments will be discarded from the opcode cache to reduce the size of the optimised code. Disabling this configuration directive may break applications and frameworks that rely on comment parsing for annotations, including Doctrine, Zend Framework 2 and PHPUnit.
225+
- `PHP_OPCACHE_REVALIDATE_FREQ` (default `60`) How often to check script timestamps for updates, in seconds. 0 will result in OPcache checking for updates on every request.
226+
- `PHP_OPCACHE_JIT` (default `1255`) This set JIT configuration mode. Check the [OPcache JIT configuration](https://www.php.net/manual/en/opcache.configuration.php#ini.opcache.jit) for more information.
227+
- `PHP_OPCACHE_JIT_BUFFER_SIZE` (default `128M`) The amount of shared memory to reserve for compiled JIT code. A zero value disables the JIT.
228+
220229
### Auto configuration and Nextcloud updates
221230
The image comes with special config files for Nextcloud that set parameters specific to containerized usage (e.g. `upgrade-disable-web.config.php`) or enable auto configuration via environment variables (e.g. `reverse-proxy.config.php`). Within the image, the latest version of these config files are located in `/usr/src/nextcloud/config`.
222231

0 commit comments

Comments
 (0)