在 MAMP 中停止缓存 PHP 5.5.3

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19073270/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 18:48:12  来源:igfitidea点击:

Stop caching for PHP 5.5.3 in MAMP

phpcachingmampphp-5.5

提问by Daron Spence

Installed MAMP on a new Macbook with PHP 5.5.3.

在带有 PHP 5.5.3 的新 Macbook 上安装 MAMP。

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?

我进入 php.ini 并禁用所有新的 OPcache 并将默认缓存时间设置为 0。向文档添加标题以强制不缓存。还是一样的问题。这到底是怎么回事?

The network tab is showing a HTTP 200 request, so any new HTML in the index.phpfile 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?

网络选项卡显示 HTTP 200 请求,因此index.php文件中的任何新 HTML 都可以正常呈现,但是需要由服务器呈现的新 PHP 会延迟并且不会呈现,直到经过我不知道的预定时间集改变。这是怎么回事?

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

我也在 Safari 中检查了这个,所以它绝对是一个服务器的东西,它阻止了文件的呈现。

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.

有趣的事实是,如果我进入 MAMP 并将 PHP 版本更改为旧版本(PHP 5.2 或其他版本),它将正常呈现,没有“缓存问题”。切换到 PHP 5.5,它挂了。在 MAMP 首选项中,5.5 的缓存选项甚至不存在并且会自动禁用。

回答by Jonathan Kaiser

Disable OPCache

禁用 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.

MAMP 现在默认打开 OPCache,您可以通过编辑 php.ini 文件来禁用它。确保您编辑了正确的 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.

我自己也遇到了同样的问题。默认情况下,PHP 5.5.3 版的 MAMP 运行 OPcache,但您无法像使用旧版 PHP 5.2.17 那样在 GUI 中关闭它。您必须手动注释掉 php.ini 文件(MAMP/bin/php/[version]/conf/php.ini)末尾的所有 OPcache 行,并确保停止和启动服务器以进行更改影响。

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.

我更新了 URI,更改也可以通过更改 php 文件夹下的 /conf/ 来反映,但似乎 MAMP 在 restart 后会忽略这些

回答by Joeri

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

我添加了opcache_reset(); 在我的主要 PHP 中停止这种缓存。

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

删除它对php5.5.3/conf/php.ini我没有任何帮助。

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.

原来还有一个/Applications/MAMP/bin/php/php5.5.3/conf/php.ini. 如果我在那里评论它,它会起作用。

回答by Lagi

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

1) 在 /Applications/MAMP/bin/php/php5.5.3/conf/php.ini
2) 设置 opcache.revalidate_freq=0
3) 重启 MAMP

回答by Feanne

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.

我花了很长时间才发现这是 MAMP 问题!为什么默认情况下会启用 OPcache——并且需要修改 php.ini 来禁用——在一个应该用于测试网站的应用程序中?无论如何,我通读了整个线程并尝试了各种解决方案。

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

opcache_reset();

<?php opcache_reset(); ?>
  • Must be added in the webpage code.
  • Forces all scripts to be reloaded.
  • Works without restarting MAMP server.
  • 必须在网页代码中添加。
  • 强制重新加载所有脚本。
  • 无需重新启动 MAMP 服务器即可工作。

Server configuration solutions

服务器配置解决方案

Important:Use the php.inifile in /Applications/MAMP/bin/php/php5.5.3/conf/php.iniand not in /Applications/MAMP/conf/php5.5.3/php.ini. Adjust accordingly if you're using a different version of PHP.

重要提示:使用php.ini文件中/Applications/MAMP/bin/php/php5.5.3/conf/php.ini,而不是在 /Applications/MAMP/conf/php5.5.3/php.ini。如果您使用的是不同版本的 PHP,请相应地进行调整。

enable=0

启用=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]in下添加php.ini
  • 禁用 OPcache。
  • 需要重新启动 MAMP 服务器。

opcache.revalidate_freq=0

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_frequnder [OPcache]in php.ini.
  • Makes OPcache check for updates every 0 seconds instead of every 60 seconds.
  • Requires MAMP server restart.
  • 修改opcache.revalidate_freq[OPcache]php.ini
  • 使 OPcache 每 0 秒而不是每 60 秒检查一次更新。
  • 需要重新启动 MAMP 服务器。

Commenting out [OPcache]

注释掉 [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.
  • 注释掉 中的整个[OPcache]部分php.ini
  • 从 PHP 服务器中删除 OPcache。
  • 需要重新启动 MAMP 服务器。


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
  • 您只需要为特定项目强制刷新脚本
  • 您不想重新启动 MAMP 服务器
  • 你不想编辑 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
  • 您希望默认禁用缓存,而不必在每个项目中都这样做
  • 您对编辑 php.ini 很满意

I personally prefer enable=0since it's the simplest solution for me, and I need caching disabled by default.

我个人更喜欢enable=0它,因为它对我来说是最简单的解决方案,而且我需要默认禁用缓存。



References

参考

回答by jibiel

MAMP 3.0.7.2 for OS X

适用于 OS X 的 MAMP 3.0.7.2

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

看起来这最终是一个 GUI 选项。MAMP 3.0.7.2 for Mac OS X.

回答by Huroman

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

花了大约 1 个小时试图弄清楚它可能是什么是痛苦的。

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

我只是在代码末尾添加了这个并重新启动 MAMP。

  opcache.revalidate_freq=0
  opcache_reset();

回答by aakatheeri

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

编辑“/Applications/MAMP/conf/php5.5.3/php.ini”,搜索【OPcache】,直接在下面添加这段代码:

opcache.enable=0

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

这将在 MAMP 服务器中使用 PHP 时禁用 opcache。

回答by intheusa

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

哦,伙计,我很高兴我找到了这个线程!我正在拔头发!我昨天刚刚升级了 MAMP,直到今天在处理一个项目时才注意到这个缓存问题。以为我失去理智了。我刚刚更改了文件 opcache.enable=0 最底部的“/Applications/MAMP/conf/php5.5.3/php.ini”

回答by vr_driver

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

这在 Windows 版本的 MAMP 中也是最新的。

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

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:

我发现的另一个问题是在 QNAP NAS TS-431 上。此缓存也已启用,如果您正在处理动态更改的文件,或者尝试在其上进行开发,那么您将被扯掉头发。根据其他评论,只需将其注释掉即可。该设置位于:

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

控制面板/应用程序/Web 服务器/PHP.ini 维护。

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

再次,您将在文件底部找到设置。