serversideup / docker-php

🐳 Production-ready Docker images for PHP. Optimized for Laravel, WordPress, and more!
https://serversideup.net/open-source/docker-php/
GNU General Public License v3.0
1.74k stars 119 forks source link

Install opcache extension by default #294

Closed josiasmontag closed 6 months ago

josiasmontag commented 7 months ago

A production ready and optimized PHP image should really have the opcache extensions installed by default.

The performance gains are massive (especially for Laravel) and it is just installing the extension.

AlejandroAkbal commented 7 months ago

What! Quite weird that opcache is not installed by default, this should be prioritized

jaydrogers commented 7 months ago

What! Quite weird that opcache is not installed by default, this should be prioritized

Gimme a break guys! I'll get it merged πŸ˜†

anotherglitchinthematrix commented 7 months ago

:^) what the hell, last time I checked with php -m I think I saw opcache listed there and I'm pretty sure I've configured opcache for my needs.

anotherglitchinthematrix commented 7 months ago

Yes it's already here, it seems it's coming as default module since PHP 5, you just have to configure it.

> docker run --rm serversideup/php:8.2-fpm php -m | grep "Zend OPcache"

[18-Mar-2024 08:42:37] NOTICE: fpm is running, pid 64
[18-Mar-2024 08:42:37] NOTICE: ready to handle connections
[18-Mar-2024 08:42:37] NOTICE: systemd monitor interval set to 10000ms
Zend OPcache
Zend OPcache
[18-Mar-2024 08:42:38] NOTICE: Terminating ...
[18-Mar-2024 08:42:38] NOTICE: exiting, bye-bye!

> docker run --rm serversideup/php:8.2-cli php -m | grep "Zend OPcache"

Zend OPcache
Zend OPcache
AlejandroAkbal commented 7 months ago

Maybe it’s not on the beta?

josiasmontag commented 7 months ago

Indeed it is enabled in stable but not in the beta.

➜  ~ docker run --rm -it serversideup/php:8.2-fpm-nginx php -i | grep opcache.enable

opcache.enable => On => On
opcache.enable_cli => Off => Off
opcache.enable_file_override => Off => Off

➜  ~ docker run --rm -it serversideup/php:beta-8.3-fpm-nginx php -i | grep opcache.enable

➜  ~ 
krzysztof97 commented 6 months ago

At this moment you can just add RUN install-php-extensions opcache to your own Dockerfile.

jaydrogers commented 6 months ago

I'm working on this now if anyone is available to give me quick feedback:

Opcache will be installed.

πŸ‘‰ The question:

I am just worried about PHP developers running into local issues regarding cache. It will be easy to disable it via an ENV setting (which i will document.

Thoughts? πŸ€”

seanvandermolen commented 6 months ago

I'd prefer it enabled, but for your sanity, probably disabled.

AlejandroAkbal commented 6 months ago

Enabled since it’s main use is for production servers

jaydrogers commented 6 months ago

I put this out into the Twitterverse and it's not a strong opinion one way or the other.

Someone proposed DISABLED by default with a notice on how to enable it: https://twitter.com/NikSpyratos/status/1775524350004785259

I think that's a good approach thoughts?

sneycampos commented 6 months ago

i used to have development and production images, each one with his default tools, like xdebug in dev, opcache in prod. Documenting the path to customize these settings etc.

jaydrogers commented 6 months ago

Just shipped this to the beta images. πŸ₯³

Everything is fully documented on the live site and I put a notification if it's enabled or disabled.

image

How it works

Why I did it this way