From 452ece75c879154bfacd9b74f2fc548d2000467a Mon Sep 17 00:00:00 2001 From: Lu Ken Date: Thu, 12 Sep 2019 21:59:44 +0800 Subject: [PATCH] expose PHP opcache via environment variable for different workload --- php/Dockerfile | 18 ++++++++++++++- php/README.md | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 79 insertions(+), 1 deletion(-) diff --git a/php/Dockerfile b/php/Dockerfile index 37beeac..53153b8 100644 --- a/php/Dockerfile +++ b/php/Dockerfile @@ -19,6 +19,15 @@ RUN source /os-release && \ --path /install_root --statedir /swupd-state \ --bundles=os-core-update,php-basic --no-boot-update +RUN echo -e '\ +opcache.enable_cli=${OPCACHE_ENABLE_CLI}\n\ +opcache.memory_consumption=${OPCACHE_MEMORY_CONSUMPTION}\n\ +opcache.validate_timestamps=${OPCACHE_VALIDATE_TIMESTAMPS}\n\ +opcache.max_accelerated_files=${OPCACHE_MAX_ACCELERATED_FILES}\n\ +opcache.optimization_level=${OPCACHE_OPTIMIZATION_LEVEL}\n\ +opcache.interned_strings_buffer=${OPCACHE_INTERNED_STRINGS_BUFFER}\n\ +opcache.revalidate_freq=${OPCACHE_REVALIDATE_FREQ}' >> /install_root/usr/share/defaults/php/php.ini + # For some Host OS configuration with redirect_dir on, # extra data are saved on the upper layer when the same # file exists on different layers. To minimize docker @@ -28,9 +37,16 @@ COPY --from=clearlinux/os-core:latest / /os_core_install/ RUN cd / && \ find os_core_install | sed -e 's/os_core_install/install_root/' | xargs rm -d &> /dev/null || true - FROM clearlinux/os-core:latest +ENV OPCACHE_REVALIDATE_FREQ=0 \ + OPCACHE_VALIDATE_TIMESTAMPS=0 \ + OPCACHE_ENABLE_CLI=1 \ + OPCACHE_OPTIMIZATION_LEVEL=0x7FFFFFFF \ + OPCACHE_MEMORY_CONSUMPTION=256 \ + OPCACHE_MAX_ACCELERATED_FILES=10000 \ + OPCACHE_INTERNED_STRINGS_BUFFER=16 + COPY --from=builder /install_root / CMD ["php","-a"] diff --git a/php/README.md b/php/README.md index ccfec38..39dad82 100644 --- a/php/README.md +++ b/php/README.md @@ -54,9 +54,71 @@ image](https://hub.docker.com/_/php). docker run -it --rm --name my-running-php clearlinux/php ``` +3. Customize OPCache parameters via environment variable, for example: + ``` + docker run -it -e "OPCACHE_ENABLE_CLI=1" clearlinux/php + ``` + *Note: please get all environment variable setting from below OPCache parameters section.* + ### Deploy with Kubernetes + +### OPCache Configurations +The OPCache parameters for PHP container could be configed via following environment variable. +These values will be set into /usr/share/defaults/php/php.ini. + +* **OPCACHE_ENABLE_CLI** + - Default Value: 1 + - Config in php.ini: opcache.enable_cli + - Descriptions: + Enables the opcode cache for the CLI version of PHP. When testing/debugging or + run **PHPBench**, set 1 + +* **OPCACHE_VALIDATE_TIMESTAMPS** + - Default Value: 0 + - Config in php.ini: opcache.validate_timestamps + - Descriptions: + If enabled, OPcache will check for updated scripts every opcache.revalidate_freq seconds. + If the source of workload is cloned by git via sidecar design pattern and will be updated + often, set 1 + +* **OPCACHE_REVALIDATE_FREQ** + - Default Value: 0 + - Config in php.ini: opcache.revalidate_freq + - Descriptions: + How often to check script timestamps for updates, in seconds. 0 will result in + OPcache checking for updates on every request. + +* **OPCACHE_INTERNED_STRINGS_BUFFER** + - Default Value: 16 + - Config in php.ini: opcache.interned_strings_buffer + - Descriptions: + The amount of memory used to store interned strings, in megabytes. + +* **OPCACHE_OPTIMIZATION_LEVEL** + - Default Value: 0x7FFFFFFF + - Config in php.ini: opcache.optimization_level + - Descriptions: + A bitmask that controls which optimisation passes are executed. + +* **OPCACHE_MEMORY_CONSUMPTION** + - Default Value: 256 + - Config in php.ini: opcache.memory_consumption + - Descriptions: + The size of the shared memory storage used by OPcache, in megabytes. + You can use the function opcachegetstatus() to tell how much memory opcache + is consuming and if you need to increase the amount + +* **OPCACHE_MAX_ACCELERATED_FILES** + - Default Value: 10000 + - Confg in php.ini: opcache.max_accelerated_files + - Descriptions: + Controls how many PHP files, at most, can be held in memory at once. It's important + that your project has LESS FILES than whatever you set this at. + You can run `find . -type f -print | grep php | wc -l` to quickly calculate the number + of files in your codebase. + ## Build and modify: