-
Notifications
You must be signed in to change notification settings - Fork 24
Opcache should be disabled by default #129
Comments
So that explains why file changes often don't take effect immediately, +1 for this! |
For my own curiosity, before we just blanket remove OPCache, can we tweak a setting which would tell OPCache to use the files timestamp for validation and see if we are still seeing the need for a multiple refreshes to see changes? @bencroker can you ssh into nitro ( sudo vi /etc/php/7.4/fpm/conf.d/10-opcache.ini Add the the following into the file:
Finally restart php-fpm using:
If you are logged into your control panel, under Utilities > PHP Info you should see the following:
|
@jasonmccallister Without doing this, I see that OPCache does appear to be validating timestamps, as the changes are detected, however the changes are sometimes detected immediately and sometimes takes up to a few seconds to take effect, which is rather frustrating during development. |
@bencroker you are right, can you instead add this setting:
and then restart php-fpm? |
Changed Could it be that when I edit a file, it takes some time for Nitro to detect and mount the modified file into Multipass? |
Tested with a PHP file and changes take effect immediately. So, this appears to have to do with compiled twig templates being cached. I've submitted craftcms/cms#6046 to Craft core which should help resolve this. As per my tests, with the PR above, OPCache can remain enabled as it is. |
What would the benefit be of having opcache available in a local dev environment? |
It is faster and when @bencroker and I were troubleshooting, there was still a delay in the twig template rendering. His PR will resolve that when using |
Right, I know Re: the PR @bencroker my question would be... why does this only show up when doing local dev with Nitro? |
@khalwat Possibly because of the way Nitro mounts the directory, but that's more of a question for @jasonmccallister. |
@khalwat I think it surfaced in Nitro but I have seem the exact same behavior when running Craft in Docker. |
craftcms/cms#6046 was rejected so this issue remains unresolved. |
Twig determines whether a template needs to be recompiled by comparing the template file’s modify time with the compiled PHP file’s modify time. But with OPcache enabled, the new template file modify time might not be immediately available, as OPcache will return the cached modify time instead. When you disable Twig “caching”, you’re disabling its ability to save the compiled templates as PHP files for future requests, which does technically solve the OPcache conflict (no precompiled files to compare against in the first place), but you’d be throwing the baby out with the bathwater; having Twig save compiled templates as PHP files is a huge timesaver, versus recompiling templates on every request. If we have to choose one, OPcache is the one that should be disabled, not Twig caching. |
Hmm, would be interesting to add a custom loader that does not use a filesystem: https://twig.symfony.com/doc/3.x/api.html#create-your-own-loader |
Either way, will make those changes for the next beta release. |
We do use our own loader, but that wouldn’t solve this problem. That’s just for loading the actual template files, which are always going to be file-based, so will suffer from this problem as long as OPcache is enabled. |
This will be released with beta 3. |
@jasonmccallister Was this released with beta 3? |
Hi @jskrivanek this was released with a beta of Nitro v1. We are actively working on Nitro V2 that is based on Docker instead of Multipass. If you are referring to v2 can you please create a new issue and describe any issues you are having? |
Usually ends up being a pain for local development
The text was updated successfully, but these errors were encountered: