Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stop caching for PHP 5.5.3 in MAMP

Disable OPCache

MAMP now turns on OPCache by default, you can disable it by editing your php.ini file. Make sure you edit the correct php.ini.

I was running into the same problem myself. MAMP with PHP version 5.5.3 runs OPcache by default, but you can't turn it off in the GUI like you can with the older PHP version 5.2.17. You have to manually comment out all the OPcache lines at the end of the php.ini file (MAMP/bin/php/[version]/conf/php.ini) and make sure to stop and start the servers for the changes to take effect.

I updated the URI, the changes can be reflective by also changing /conf/ under the php folder, but it seems MAMP will ignore these after restart.


I added opcache_reset(); in my main PHP to stop this caching.

Removing it from php5.5.3/conf/php.ini did nothing for me.

Edit

Turns out there also is a /Applications/MAMP/bin/php/php5.5.3/conf/php.ini. It works if I comment it out there.


1) in /Applications/MAMP/bin/php/php5.5.3/conf/php.ini
2) set opcache.revalidate_freq=0
3) restart MAMP


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

  • http://php.net/manual/en/function.opcache-reset.php
  • http://php.net/manual/en/opcache.configuration.php

MAMP 3.0.7.2 for OS X

It looks like this is finally a GUI option. MAMP 3.0.7.2 for Mac OS X.


It was painful spending around 1 hour trying to figure out what could it be.

I just added this at the end of the code and restart MAMP.

  opcache.revalidate_freq=0
  opcache_reset();

Edit "/Applications/MAMP/conf/php5.5.3/php.ini", and search for [OPcache] and add this code under it directly:

opcache.enable=0

This will disable opcache in when use PHP in MAMP server.