'Stop caching for PHP 5.5.3 in MAMP

Installed MAMP on a new Macbook with PHP 5.5.3.

Reload and refresh do nothing. Still nothing. Google around for a few minutes trying to find out what is wrong, come back and refresh. It works. What the heck?

I went into php.ini and disabled all the new OPcache and set the default cache time to 0. Added headers to the document to force no caching. Still same problem. What the heck is going on here?

The network tab is showing a HTTP 200 request, so any new HTML in the index.php file renders fine, but new PHP that needs to be rendered by the server is delayed and not rendered until some predetermined set of time passes that I don't know how to change. What's going on?

I checked this in Safari too so it is definitely a server thing that is keeping the file from rendering.

Interesting fact though, if I go into MAMP and change the PHP version to the old one (PHP 5.2 or something) it will render normally, with no "caching issues". Switch to PHP 5.5 and it hangs up. In the MAMP preferences caching options for 5.5 don't even exist and are automatically disabled.



Solution 1:[1]

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.

Solution 2:[2]

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.

Solution 3:[3]

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

Solution 4:[4]

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

Solution 5:[5]

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.

Solution 6:[6]

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();

Solution 7:[7]

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.

Solution 8:[8]

Oh man am I glad I found this thread! I was pulling my hair out! I just upgraded MAMP yesterday and didn't notice this caching issue until today while working on a project. Thought I was losing my mind. I just changed "/Applications/MAMP/conf/php5.5.3/php.ini" very bottom of file opcache.enable=0

Solution 9:[9]

This is also current in the Windows version of MAMP as well.

C:\MAMP\conf\php5.6.3\php.ini

It's listed at the very bottom of the file.

The other problem I found, was on a QNAP NAS TS-431. This caching is also enabled, and if you are working with dynamically changing files, or try to develop on it, you'll be ripping out your hair. As per the other comments, just comment it out. The setting is located in:

Control Panel/Applications/Web Server/PHP.ini Maintenance.

Once again, you'll find the settings at the bottom of the file.

Solution 10:[10]

Open your Mamp panel on the right top corner click "Preferences" a pop will open ,there is a option to "off" the php cache. It works like charm,No need to modify any other files. enter image description here

Solution 11:[11]

For those using MAMP 6.x you have to disable the setting in the UI otherwise MAMP will overwrite your PHP files the next time you restart apache.

The setting is in the PHP setting as shown here:

enter image description here

Change the default OPcache setting to off and click Save. After saving restart the Apache service.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 donohoe
Solution 3 Lagi
Solution 4 Community
Solution 5 jibiel
Solution 6 Huroman
Solution 7 aakatheeri
Solution 8 intheusa
Solution 9
Solution 10 Aditya
Solution 11 antfx