Took me so long to figure out it was a MAMP problem! Why would OPcache be enabled by default-- and require php.ini tinkering to disable-- in an app that's supposed to be used for testing websites? Anyway, I read through this whole thread and tried the various solutions.
Here are my notes on how each solution works and considerations for selecting a solution.
Each solution works on its own; no need for redundancy.
Webpage code solution
opcache_reset();
<?php opcache_reset(); ?>
- Must be added in the webpage code.
- Forces all scripts to be reloaded.
- Works without restarting MAMP server.
Server configuration solutions
Important: Use the php.ini
file in /Applications/MAMP/bin/php/php5.5.3/conf/php.ini
and not in
/Applications/MAMP/conf/php5.5.3/php.ini
. Adjust accordingly if you're using a different version of PHP.
enable=0
[OPcache]
zend_extension="/Applications/MAMP/bin/php/php5.5.3/lib/php/extensions/no-debug-non-zts-20121212/opcache.so"
opcache.memory_consumption=128
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=4000
opcache.revalidate_freq=60
opcache.fast_shutdown=1
opcache.enable_cli=1
enable=0
- Must be added under
[OPcache]
in php.ini
.
- Disables OPcache.
- Requires MAMP server restart.
opcache.revalidate_freq=0
[OPcache]
zend_extension="/Applications/MAMP/bin/php/php5.5.3/lib/php/extensions/no-debug-non-zts-20121212/opcache.so"
opcache.memory_consumption=128
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=4000
opcache.revalidate_freq=0
opcache.fast_shutdown=1
opcache.enable_cli=1
- Modify
opcache.revalidate_freq
under [OPcache]
in php.ini
.
- Makes OPcache check for updates every 0 seconds instead of every 60 seconds.
- Requires MAMP server restart.
Commenting out [OPcache]
;[OPcache]
;zend_extension="/Applications/MAMP/bin/php/php5.5.3/lib/php/extensions/no-debug-non-zts-20121212/opcache.so"
;opcache.memory_consumption=128
;opcache.interned_strings_buffer=8
;opcache.max_accelerated_files=4000
;opcache.revalidate_freq=60
;opcache.fast_shutdown=1
;opcache.enable_cli=1
- Comment out the entire
[OPcache]
section in php.ini
.
- Removes OPcache from the PHP server.
- Requires MAMP server restart.
Considerations
Choose the webpage code solution if:
- You just need to force script refreshing for a particular project
- You don't want to restart the MAMP server
- You don't want to edit php.ini
Choose a server configuration solution if:
- You want to disable caching by default instead of having to do it in every project
- You're comfortable with editing php.ini
I personally prefer enable=0
since it's the simplest solution for me, and I need caching disabled by default.
References