130

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.

tereško
  • 58,060
  • 25
  • 98
  • 150
Daron Spence
  • 1,583
  • 3
  • 14
  • 17
  • 4
    I know that this is not a solution to your problem, but I'm personally not a big fan of MAMP, as, especially not when installing a custom stack is so easy - Here's a pretty swift guide to install a stack using homebrew: https://github.com/josegonzalez/homebrew-php – mewm Sep 29 '13 at 00:48
  • @mewm I didn't realise it could be so easy. Cheers! Used this to get going with nginx in just a few keystrokes. http://learnaholic.me/2012/10/10/installing-nginx-in-mac-os-x-mountain-lion/ – willdanceforfun Dec 22 '13 at 05:06

11 Answers11

214

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.

Jonathan Kaiser
  • 2,156
  • 1
  • 12
  • 2
  • 4
    I had the same issue and fixed it by commenting out the opcache lines. It's kind of puzzling that you have to go into the php.ini file to change this around. It's actually quite misleading, since it would seem like you have all the caching options given in the MAMP->Preferences drop-down box. – JaredH Oct 05 '13 at 23:17
  • 20
    I'm wondering which part of their body MAMP creators were using to think while adding this "cool feature". – Sergii Oct 23 '13 at 15:18
  • I thought I had something wrong with my ModX install, but no, your answer seems to have fixed it. Thanks. Further to that, I also reverted to the older version. It now runs much better. – vr_driver Oct 31 '13 at 13:53
  • 68
    Note that the `php.ini` file you want to edit is in /bin, *not* in /conf. My full path was `/Applications/MAMP/bin/php/php5.5.3/conf/php.ini`. – Husky Nov 07 '13 at 20:48
  • I've submitted a bug report, hopefully they'll disable it by default in a future version: http://bugs.mamp.info/view.php?id=4296 – Husky Nov 07 '13 at 20:53
  • @Husky +1 for note on folder location. I'm running latest MAMP to-date and the `conf/php.ini` refers to the one in the `bin` (not the `conf` at the root of the MAMP Application folder). – shennan Nov 11 '13 at 15:10
  • Within my php.ini, I can only see xcache and eaccelerator, I've tried searching for opcache etc..., however nothing shows up. I am using 5.4.4 and accessing the conf file (not the root location). –  Nov 25 '13 at 19:53
  • @Husky, I've edited the original post to point to this, as I noticed my original edit was only temporary. –  Jan 31 '14 at 20:13
  • I change the line opcache.revalidate_freq=60 to opcache.revalidate_freq=2 – orafaelreis Mar 19 '14 at 14:27
  • I don't normally post 'me too' comments, but this was easily the most frustrating problem I have ever encountered. How ridiculous that caching would be enabled by default!! I've been trying to debug my coding IDE settings for days before I discovered this! – 1owk3y Oct 07 '14 at 23:42
  • What if you don't have MAMP? – Alexander Kleinhans May 31 '15 at 12:39
  • FWIW I had to restart php-fpm before the change took effect. Restarting Apache was insufficient. Pulled my hair out for a while over this. – Danny May 03 '16 at 21:55
  • opcache.enable=0 did it for me – Klevis Miho Aug 23 '22 at 07:21
39

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.

donohoe
  • 13,867
  • 4
  • 37
  • 59
Joeri
  • 2,214
  • 24
  • 24
28

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

Lagi
  • 495
  • 4
  • 12
  • 2
    This seems to work. I enjoyed implementing this solution better than commenting it all out. But is there a difference? – Jonathan Feb 07 '14 at 08:59
  • This is a troubled soul from the future, in 2022 with PHP 8 and MAMP 6.6 this still works great! – Mark Kazakov Jul 04 '22 at 10:50
12

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

Community
  • 1
  • 1
Feanne
  • 473
  • 1
  • 5
  • 10
4

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.

jibiel
  • 8,175
  • 7
  • 51
  • 74
  • This doesn't disable OPCache apparently. Mine was still active even with this setting "off". – auco Apr 03 '19 at 06:50
2

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();
Huroman
  • 29
  • 4
2

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.

aakatheeri
  • 63
  • 6
2

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

intheusa
  • 89
  • 1
  • 10
1

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.

vr_driver
  • 1,867
  • 28
  • 39
1

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

Ady
  • 67
  • 1
  • 4
  • @AbdurRehman, this is a valid answer to the original question. It is not asking a new question. – antfx Apr 22 '22 at 09:30
0

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.

antfx
  • 3,205
  • 3
  • 35
  • 45