I recently moved to PHP 5.4 and installed OPCache, it's very powerful!
How can I temporarily disable the cache?
I tried :
ini_set('opcache.enable', 0);
But it has no effect.
Thanks
Using OPcache with WordPressOPcache is enabled by default which you can see in a phpinfo.
In the SOFTWARE section of the cPanel home screen, click Select PHP Version. Select the check box next to the opcode caching extension you want to enable: If you are using PHP version 5.4 or older, select apc. If you are using PHP version 5.5 or newer, select opcache.
To check if the caching engine works properly, just look at the percentages at the “Overview” tab at the opcache-gui page. If the memory usage and hit rate values are greater than zero, it means that the OpCache is caching the PHP code and the cached files are being used to handle the requests.
What is OPcache or PHP Opcode Caching? OPcache is a type of OPcode caching. This kind of caching compiles human-readable PHP code to code your server understands which is called opcode. This occurs when the PHP file loads on a web page for the first time.
Once your script runs, it's too late to not cache the file. You need to set it outside PHP:
If PHP runs as Apache module, use an .htaccess
file:
php_flag opcache.enable Off
If PHP runs as CGI/FastCGI, use a .user.ini
file:
opcache.enable=0
In all cases, you can also use good old system-wide php.ini
if you have access to it.
opcache.enable is PHP_INI_ALL which means that ini_set() does work, but only for current request to disable OPcache caching for the remainder of scripts compiled in your current request. (You can't force enabling). It reverts back to the system default for other requests. By this stage, the request script will already have been cached, unless you do the ini_set in an auto_prepend_file script.
The system defaults (PHP_INI_SYSTEM) are latched as part of PHP system startup and can't be reread. So in the case of Apache for example, you need to restart Apache to change / reload these.
The .htaccess
php_flag
directives only apply if you are running mod_php or equivalent. They and .user.ini
files are PHP_INI_PERDIR, which will also be latched at request activation.
Now to the Q that I think that you might be asking. If you have a dev system then the easiest way is to set opcache.enable=0
in the appropriate INI file and restart your webserver. Set it back to =1
and restart again when you are done.
Also consider (in the dev context) setting opcache.validate_timestamps=on
and opcache.revalidate_freq=0
. This will keep OPcache enabled but scripts will be stat'ed on every compile request to see if they are changed. This gives the best of both worlds when developing.
Also read up on the opcache.blacklist_filename
directive. This allow you to specify an exclusion file, so if this contains /var/www/test
, and the web service docroot is /var/www
then any scripts in the /var/www/test*
hierarchies will not be cached.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With