Open lenaxia opened 1 year ago
I'm able to demonstrate that opcache is working using the opcache script here: https://github.com/amnuts/opcache-gui/blob/master/index.php
and executing this in the pod with www-data
permissions: wget https://raw.githubusercontent.com/amnuts/opcache-gui/master/index.php -O /var/www/html/opcache.php
Just with regular usage on a single user I'm able to hit 99% cache hit rate with 2GB, and I can see the cache size change based on the settings I've defined above. Looks like OPCache is enabled by default.
Others who are more familiar with php's OPCache can chime in, as I haven't worked with it much in the past, but I did do some looking around in the mean time, because I'd like to understand how to help better. Here's some questions and suggestions I came up with:
For starters, can you try without php_admin_value[]
, so for instance just opcache.enable = 1
instead of php_admin_value[opcache.enable] = 1
?
Could you also post your k8s configMap for this file?
Could you check if there's already a php.ini
file in somewhere like /etc/php/PHP_VERSION/apache2
? Everything I'm seeing mentions php.ini
.
Do you get the same error if you change opcache.memory_consumption = 1024
to a higher value?
Finally, here's a couple links I found when trying to check nextcloud's other repos on this:
This is the apache docker file (but the fpm file seems to look the same) which shows recommended settings: https://github.com/nextcloud/docker/blob/c1a52325422d08def6aa9d30028e04a96432abf0/25/apache/Dockerfile#L92
this is a thread discussing opcache in nextcloud/server. it's very long, so grab a cup of tea: https://github.com/nextcloud/server/issues/31223
Regardless of what we find, it might make sense to put in some documentation in the README on how to do this properly, when we figure it out. I'd be happy to review a PR from you or anyone else reading to get this cleared up. It looks like there's a lot of confusion on this accross the docker repo, server repo, and forums with differing resolutions, so at least solidifying how we do things here would be a good first step.
1. For starters, can you try without `php_admin_value[]`, so for instance just `opcache.enable = 1` instead of `php_admin_value[opcache.enable] = 1`?
It is a boolean, so php_admin_value[]
is incorrect. Please read how booleans are handled here https://www.php.net/manual/en/configuration.changes.php.
php_admin_flag[opcache.enable] = 1
opcache.save_comments
can probably not be set via php_admin_flag on your platform (if it has already been set in php.ini for example), as it can only be changed via PHP_INI_SYSTEM
, which you can find more about here: https://www.php.net/manual/en/configuration.changes.modes.php. That means once defined, it can not be overridden.
php_admin_flag[opcache.save_comments] = 1
Setting opcache.save_comments
via the php.ini (or an included mod conf file) would work, but you'd need access to that.
And what are you even trying to do here? Assign 97% of the opcache memory to strings? Yeah that's a great idea. /s
php_admin_value[opcache.interned_strings_buffer] = 1000
php_admin_value[opcache.memory_consumption] = 1024
Apart from the IMHO silly mem allocation, you can also probably not set it via a php_admin_value, if it has been set already once. Then you can only set it for the entire php server and all its pools via the php.ini. You can use https://github.com/gordalina/cachetool to find the actual status, or otherwise just have a look at the functions opcache_get_configuration()
and opcache_get_status()
.
You will probably find out, that https://bugs.php.net/bug.php?id=71042 is indeed still active and PHP_INI_SYSTEM
also still means that it can not be set via a php_admin_value/flag as per the link above, once they've been set by your hosting provider.
@makuser thanks for all your input, but please also remember to be kind when responding to issues. I see you reacted with 👎 to my comment and I'm not sure why, but if you have a solution or want to improve docs, we're happy to take a look at PR either here or in another nextcloud repo upstream.
PHP isn't my strong point, but especially if it's already being done in the nextcloud/server or nextcloud/docker repos, we're happy to consider any PRs that would improve the experience of this helm chart 💙 If you do submit a PR, remember to link back to this issue, so that the community can stay on top of the progress and we can close this issue if a fix is found.
Hi, I have this warning. What is the solution?
OK, so I have this warning now too, and I've been investigating. I found this related issue upstream: https://github.com/nextcloud/docker/issues/2184
Looks like the docker image sets the following in ${PHP_INI_DIR}/conf.d/opcache-recommended.ini
.
The Nextcloud maintained all-in-one docker image sets slightly different values, which you can view here.
I checked on my nextcloud:29.0.1-fpm-alpine
container, and ${PHP_INI_DIR}
is indeed set to /usr/local/etc/php
, so I think to override the existing values, you need to override those values. Here's that file, which is auto-generated from the upstream docker repo, on my container:
$ cat /usr/local/etc/php/conf.d/opcache-recommended.ini
opcache.enable=1
opcache.interned_strings_buffer=32
opcache.max_accelerated_files=10000
opcache.memory_consumption=128
opcache.save_comments=1
opcache.revalidate_freq=60
opcache.jit=1255
opcache.jit_buffer_size=128M
What's curious is that if you have nginx enabled, which I do, we don't use that same directory: https://github.com/nextcloud/helm/blob/3dfd22ed39d628c10868ec240b9e94dd5ee928f0/charts/nextcloud/templates/_helpers.tpl#L288-L292
So, even though I have the following set in my values.yaml, it doesn't actually take effect, and I still get the same warning:
nextcloud:
phpConfigs:
opcache.conf: |
php_admin_value[opcache.enable] = 1
php_admin_value[opcache.save_comments] = 1
php_admin_value[opcache.interned_strings_buffer] = 1000
php_admin_value[opcache.memory_consumption] = 1024
php_admin_value[opcache.max_accelerated_files] = 30000
php_admin_value[opcache.validate_timestamps] = 0
php_admin_value[opcache.revalidate_freq] = 60
php_admin_value[memory_limit] = -1
Wait! scratch some of that, maybe all of that on still getting the warning. I recently restarted the container and it looks like the new warning I'm getting is:
The PHP OPcache module is not properly configured. The OPcache buffer is nearly full. To assure that all scripts can be hold in cache, it is recommended to apply "opcache.memory_consumption" to your PHP configuration with a value higher than "1024".. For more details see the documentation ↗
so maybe the values are taking effect and what I said about them not taking effect is just false. I am also getting the following in my nextcloud.log that @lenaxia mentioned in their original post here:
Zend OPcache can't be temporary enabled (it may be only disabled till the end of request) at Unknown#0
🤔 I'm not sure why though. If it's helpful, I'm currently NOT using redis or valkey or anything else. This is JUST the nextcloud:29.0.1-fpm-alpine
container... Update, found this blog post which says:
It appears that PHP isn’t amused when you try to enable the OPcache again, when it’s already enabled. It does appear to be just a cosmetic issue and doesn’t actually impact the functionality of the PHP code itself. Either way, in this case the fix was to just remove the OPcache setting from PHP-FPM and keep it enabled in the default php.ini file.
So, the solution here is to adjust the values as you need directly the way you were doing @lenaxia to whatever your instance needs, however, don't include the php_admin_value[opcache.enable] = 1
and you won't get the Zend OPcache can't be temporary enabled
error.
Edits: tried to update as I was learning, and reduced some extra text by moving them to links.
There are the values that worked for me:
nextcloud:
phpConfigs:
opcache.conf: |
php_admin_value[memory_limit] = -1
php_admin_value[opcache.jit_buffer_size] = 8M
php_admin_value[opcache.interned_strings_buffer] = 64
php_admin_value[opcache.memory_consumption] = 1G
php_admin_value[opcache.max_accelerated_files] = 30000
php_admin_value[opcache.validate_timestamps] = 0
php_admin_value[opcache.revalidate_freq] = 60
Note: The upstream container already sets php_admin_value[opcache.enable] = 1
, so please do not set that again in the nextcloud.phpConfigs
or you will get the following error:
Zend OPcache can't be temporary enabled (it may be only disabled till the end of request) at Unknown#0
@lenaxia and @mike-pisman let me know if this works for you!
I'll close this in a month or two if I don't hear anything back from either of you, however if I do close it before either of you are able to respond, you can still respond to the closed issue, and if needed, I, or another nextcloud maintainer/collaborator/membor, can reopen it for you :)
Sorry friends. I lied apparently, as I now have the following note in the admin overview again after around an hour or so:
The PHP OPcache module is not properly configured. The OPcache buffer is nearly full. To assure that all scripts can be hold in cache, it is recommended to apply "opcache.memory_consumption" to your PHP configuration with a value higher than "128".. For more details see the documentation ↗.
What in the world have I done wrong now... 🤔 Looking into it...
The message in the admin overview is gone again 🤔 perhaps it's one of the apps I'm using? I am recognize, photos, memories, and news, which could all be big memory hogs, but I'm not sure...
Hi, I'm trying to figure out the proper way to configure OPCache based on the helm chart.
I get the following warning in my administration panel:
The PHP OPcache module is not properly configured. See the [documentation ↗](https://docs.nextcloud.com/server/25/go.php?to=admin-php-opcache) for more information. The OPcache buffer is nearly full. To assure that all scripts can be hold in cache, it is recommended to apply opcache.memory_consumption to your PHP configuration with a value higher than 1024.
I am currently trying to configure my OPCache using these configs:
My
nextcloud.log
shows this after startup:Zend OPcache can't be temporary enabled (it may be only disabled till the end of request)
What is the correct way to enable OPCache using the helm chart?