I am trying to enable opCache on my server (ubuntu 12.04 LTS
, running apache 2.4.7
with PHP Version 5.5.10-1+deb.sury.org~precise+1
).
For some reason there is a lot of conflicting documentation about PHP OPcache for PHP v5.5 (the version that first supported it), with some web pages saying it is enabled by default and others saying it is compiled, but not enabled, by default.
Going off my memory only, I think I've seen PHP 5.5 and 5.6 installations where OPcache was indeed compiled but not yet enabled. This would explain why default php.ini
line shows disabled. The confusion is likely due to the various ways in which PHP can be compiled.
Anyway, for various reasons it seems PHP 7+ pretty much always has OPcache enabled by default, and again, avoiding complex discussions re: compiling.
All that said, the OP question is really for checking if OPcache is enabled or not (only).
To that end, there is a special function opcache_get_status
for this, which can accept arrays too. Going forward, this function will probably become more popular as it is more tuned to explaining the OPcache configuration settings than php.ini
and can be used in various scripts, etc.
Here's a quick example:
Ref: https://www.digitalocean.com/community/questions/enable-php-5-5-opcache-on-ubuntu-14-04-with-nginx-and-php-fpm?comment=25376