Enabling OPcache in Php Docker boosts the performance of the websites. It is extremely easy to install, enable and manage the OPcache in the Php Docker.
Bobcares answers all questions no matter the size, as part of our Docker hosting support Service
Let us take a look at enabling OPcache in docker Php in detail.
OPcache
OPcache is a type of caching system that saves precompiled script bytecode on a server’s memory called a cache, allowing a web page to load faster each time a user visits it. And, OPcache is built into PhP to help the users accelerate their website performance. In short, OPcahce is a great performance booster tool that runs with the docker Php.
Speeding up PHP Docker with OpCache
PHP includes a caching engine called OPcache. When enabled, it significantly improves the performance of PHP-powered websites. OPcache improves PHP performance by storing precompiled script bytecode in shared memory, eliminating the need for PHP to load and parse scripts on each request, according to php.net.
Installing OpCache
Installing OpCache in the image requires only one step. Hence Include the line given below on the Docker file.
# docker-php-ext-install opcache
Enabling OpCache
A user can change the settings for OpCache to allow for more files in the cache. Hence, the user must also disable the re-validation of files in production. After that, the user can create a file with the name opcacache.ini and include it in the image. the user must make sure that the file consists of an environment to enable validation for local development
# Dockerfile
ENV PHP_OPCACHE_VALIDATE_TIMESTAMPS="0"
ADD opcache.ini "$PHP_INI_DIR/conf.d/opcache.ini"
# opcache.ini
[opcache]
; maximum memory that OPcache can use to store compiled PHP files, Symfony recommends 256
opcache.memory_consumption=192
; maximum number of files that can be stored in the cache
opcache.max_accelerated_files=20000
; validate on every request
opcache.revalidate_freq=0
; re-validate timestamps, by default set to false (0), can be overridden in local docker-compose
opcache.validate_timestamps=${PHP_OPCACHE_VALIDATE_TIMESTAMPS}
opcache.interned_strings_buffer=16
opcache.fast_shutdown=1
And, when runningdocker-compose
locally a user can include the environment variable PHP_OPCACHE_VALIDATE_TIMESTAMPS: 1
for the app container.
# docker-compose.yml
services:
app:
environment:
PHP_OPCACHE_VALIDATE_TIMESTAMPS: 1
[Need assistance with similar queries? We are here to help]
Conclusion
To sum up, docker Php enable OPcache allows the users to make their websites run smoother and much quicker. Therefore, OPcache acts as a performance booster tool that the users can install in their docker Php within a few simple steps.
PREVENT YOUR SERVER FROM CRASHING!
Never again lose customers to poor server speed! Let us help you.
Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.
0 Comments