nierdz / wordpress-opcache-plugin

https://wordpress.org/plugins/flush-opcache/
6 stars 3 forks source link

Incompatible with opcache.file_cache_only = 1 #2

Closed ahmed-sigmalux closed 7 years ago

ahmed-sigmalux commented 7 years ago

I'm using PHP 7.1 and configured the CLI php.ini with:

opcache.enable_cli=1
opcache.file_cache_only=1

With this configuration PHP from the command line should use a file-based OPcache only. When running the vcaching plugin, however, my debug log is filled with messages stating:

Notice: Zend OPcache seems to be disabled, can't compile file in /var/www/mysite/wp-content/plugins/flush-opcache/flush-opcache.php on line 200

These messages appear to be generated by the vcaching plugin OPcache warmer. If I change opcache.file_cache_only to 0, I don't see the OPcache warning messages in my debug log anymore.

Therefore I'm led to believe there's an incompatibility with the way vcaching is warming the OPcache and the opcache.file_cache_only setting.

nierdz commented 7 years ago

I don't get why you set up OPcache this way ? Can you explain what you're trying to do ? By the way, I hit the same bug with same config so I think you should report it to https://bugs.php.net/

ahmed-sigmalux commented 7 years ago

My understanding of OPcache is that, with opcache.enable or opcache.enable_cli set to 1, cached opcodes are stored in memory for the current process only. For FPM this is OK because a process can be reused infinitely, but for CLI the OPcache is effectively useless because processes are killed after execution. Hence setting opcache.enable_cli=1 doesn't actually help anything.

Setting opcache.file_cache to a valid path allows OPcache to store cached opcodes in the filesystem, which means the cache can be loaded and used by CLI processes, even if they are loaded and killed a single time. Additionally, setting opcache.file_cache_only to 1 should use the file cache only (exactly like the setting is named), which is perfect for CLI since the processes aren't reused. Thus the ideal CLI php.ini should include:

opcache.enable_cli=1
opcache.file_cache_only=1

I got most of this information from reading the Internet, in particular this thread on stackoverflow: https://stackoverflow.com/questions/25044817/zend-opcache-opcache-enable-cli-1-or-0-what-does-it-do

nierdz commented 7 years ago

Ok, this is more clear but as the name doesn't say, OPcache, does not only cache opcode, it optimizes it before storing it and that's one of the reasons you want to enable it on CLI. To be sure all optimizations will works fine with your PHP code. To be honest, that's not really useful cause optimization are going to help you when you get lot of requests and it's rarely the situation in CLI.

With that said, I just want to add something about the way OPcache is prewarmed in my plugin. It's all made in your browser when you hit "Flush OPcache" button in admin bar. So nothing is done via CLI in this plugin and I think you can safely disable this option opcache.file_cache_only. IMHO, you can even fully disable OPcache on CLI, you'll see no difference unless you have tons of CLI requests.

nierdz commented 7 years ago

I was thinking about your problem and I just realized it was something related to another bug I corrected in 2.2 release so it should be ok now.

ahmed-sigmalux commented 7 years ago

Thanks for releasing an update. The OPcache prewarm functionality now works with opcache.file_cache_only =1.