Bobcares

Docker Php enable OPcache: Explained

by | Jul 20, 2022

 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

docker php enable 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.

GET STARTED

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

Never again lose customers to poor
server speed! Let us help you.

Privacy Preference Center

Necessary

Necessary cookies help make a website usable by enabling basic functions like page navigation and access to secure areas of the website. The website cannot function properly without these cookies.

PHPSESSID - Preserves user session state across page requests.

gdpr[consent_types] - Used to store user consents.

gdpr[allowed_cookies] - Used to store user allowed cookies.

PHPSESSID, gdpr[consent_types], gdpr[allowed_cookies]
PHPSESSID
WHMCSpKDlPzh2chML

Statistics

Statistic cookies help website owners to understand how visitors interact with websites by collecting and reporting information anonymously.

_ga - Preserves user session state across page requests.

_gat - Used by Google Analytics to throttle request rate

_gid - Registers a unique ID that is used to generate statistical data on how you use the website.

smartlookCookie - Used to collect user device and location information of the site visitors to improve the websites User Experience.

_ga, _gat, _gid
_ga, _gat, _gid
smartlookCookie
_clck, _clsk, CLID, ANONCHK, MR, MUID, SM

Marketing

Marketing cookies are used to track visitors across websites. The intention is to display ads that are relevant and engaging for the individual user and thereby more valuable for publishers and third party advertisers.

IDE - Used by Google DoubleClick to register and report the website user's actions after viewing or clicking one of the advertiser's ads with the purpose of measuring the efficacy of an ad and to present targeted ads to the user.

test_cookie - Used to check if the user's browser supports cookies.

1P_JAR - Google cookie. These cookies are used to collect website statistics and track conversion rates.

NID - Registers a unique ID that identifies a returning user's device. The ID is used for serving ads that are most relevant to the user.

DV - Google ad personalisation

_reb2bgeo - The visitor's geographical location

_reb2bloaded - Whether or not the script loaded for the visitor

_reb2bref - The referring URL for the visit

_reb2bsessionID - The visitor's RB2B session ID

_reb2buid - The visitor's RB2B user ID

IDE, test_cookie, 1P_JAR, NID, DV, NID
IDE, test_cookie
1P_JAR, NID, DV
NID
hblid
_reb2bgeo, _reb2bloaded, _reb2bref, _reb2bsessionID, _reb2buid

Security

These are essential site cookies, used by the google reCAPTCHA. These cookies use an unique identifier to verify if a visitor is human or a bot.

SID, APISID, HSID, NID, PREF
SID, APISID, HSID, NID, PREF