Stop caching for PHP 5.5.3 in MAMP

吃可爱长大的小学妹 提交于 2019-12-27 12:37:44

问题


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.


回答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.




回答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.




回答3:


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




回答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

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



回答5:


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




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



回答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.




回答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




回答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.



来源:https://stackoverflow.com/questions/19073270/stop-caching-for-php-5-5-3-in-mamp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!