c77fvq
Last Updated: February 25, 2016
·
5.356K
· nbrock

MAMP and PHP 5.5.x's default OPCache

This is somewhat of a "public service announcement" for those of you using MAMP (non-pro) for development and have recently experienced problems with code edits not being reflected when the page is refreshed. Almost like there's something caching that shouldn't be...

It turns out MAMP has enabled OPCache by default for versions of PHP 5.5.x, with a higher than desirable revalidation frequency of 60 seconds without the option within the GUI to disable this functionality. This is great for production but when working in development it can cause some serious hair pulling if you're not aware it's enabled!

This feature can be completely disabled by updating your php.ini file and restarting your MAMP server.

  1. Edit the php.ini of the version of PHP 5.5.x you're using. For example, if you're using PHP 5.5.3 you would update /Applications/MAMP/bin/php/php5.5.3/conf/php.ini

  2. Scroll to the bottom of the file and comment out the following

[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

to look like

[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

III. Save the file and restart your MAMP server.


Alternatively, you can reduce the revalidation frequency to the default value of 2 seconds by updating the following line.

opcache.revalidate_freq=60

to

opcache.revalidate_freq=2

and restarting the MAMP server.


Your sanity can now return!