简体   繁体   English

刚刚升级了 Bitnami WAMP 堆栈,现在我的 PHP 文件忽略了文件更改

[英]Just upgraded Bitnami WAMP stack, now my PHP file are ignoring file changes

Not sure what code I should put in here.不知道我应该在这里输入什么代码。 The problem is simply that I edit some text either in the HTML or PHP and reload the page "localhost/mypage" and the changes don't show.问题很简单,我在 HTML 或 PHP 中编辑了一些文本并重新加载页面“localhost/mypage”并且没有显示更改。

Every now and then it changes, but I have no idea what conditions make that happen.它时不时地发生变化,但我不知道是什么条件导致这种情况发生。 Sometimes it notices the change and sometimes it doesn't.有时它会注意到变化,有时则不会。 At first I thought it was related to include files, but it doens't seem to be.起初我以为它与包含文件有关,但似乎并非如此。

I've tried editing files on site1 and site 2 (both subfolders of localhost) and the behavior is consistent.我已经尝试在站点 1 和站点 2(本地主机的两个子文件夹)上编辑文件,并且行为是一致的。

I can literally write something as simple as:我可以从字面上写一些简单的东西:

<?php echo 'this';?>

See it on the page after load, then change it to加载后在页面上看到,然后改成

<?php echo 'that';?>

And I'll still see "this" on the page.我仍然会在页面上看到“this”。

I suspect it's some kind of caching problem, but I've put this at the top of all my files:我怀疑这是某种缓存问题,但我把它放在我所有文件的顶部:

    header('Expires: Sun, 01 Jan 2014 00:00:00 GMT');
    header('Cache-Control: no-store, no-cache, must-revalidate');
    header('Cache-Control: post-check=0, pre-check=0', FALSE);
    header('Pragma: no-cache');

Doesn't make any difference at all.根本没有任何区别。 This only started when I upgraded from Bitnami 7.0.31-1.这只是在我从 Bitnami 7.0.31-1 升级时开始的。 I tried the newest one and also downgraded to 7.2.24-0 and they're the same.我尝试了最新的,也降级到 7.2.24-0,它们是一样的。 No idea what's going on.不知道发生了什么。 Don't even know what to start.甚至不知道从什么开始。

What do you do when the site doesn't respond to simple text changes?当网站不响应简单的文本更改时,您会怎么做?

Apparently there's a caching system called "OPcache" that PHP has available that Bitnami turns on by default for some reason (or maybe the newer PHP versions do that? Not sure).显然,有一个名为“OPcache”的缓存系统,PHP 可用,Bitnami 出于某种原因默认打开(或者可能是较新的 PHP 版本这样做?不确定)。 Either way, by setting opcache.enable to 0 explicitly in the php.ini file, the behavior has stopped.无论哪种方式,通过在 php.ini 文件中将 opcache.enable 显式设置为 0,行为已停止。

That's a cache thing.那是缓存的事情。 You can "solve" it in multiple ways.您可以通过多种方式“解决”它。

1) When you refresh don't just f5 but use R+F5 (cache refresh) 1)当你刷新不只是 f5 而是使用 R+F5 (缓存刷新)

2) In most browsers in the developer console when you have it open you can select to flush cache automatically. 2)在开发者控制台中的大多数浏览器中,当您打开它时,您可以 select 自动刷新缓存。

3) When you have the dev console open and you right click the refresh button on a page you have the options to cache refresh 3)当您打开开发控制台并右键单击页面上的刷新按钮时,您可以选择缓存刷新

Those 3 solutions should fix your issue.这 3 个解决方案应该可以解决您的问题。 Mostly this kind of stuff happens with css that doesn't show the changes if you haven't cached refresh.大多数情况下,如果您没有缓存刷新,css 不会显示更改。

OPCache OPCache

Like the poster not_a_generic_user stated in his own comment OPCache will be the te reason why most people tend to get confused by this.就像张贴者 not_a_generic_user 在他自己的评论中所说的那样,OPCache 将是大多数人对此感到困惑的原因。 This is something Bitnami enabled(2) by default is newer versions.这是 Bitnami 默认启用的 (2) 是较新版本。 It's been included in PHP 5.5.0 and newer.它已包含在 PHP 5.5.0 和更新版本中。

Okay fun... but i don't want it running?好吧有趣...但我不想让它运行?

Like stated before you can disable OPCache in your php.ini but opcache.enable won't always fix it entirely.如前所述,您可以在 php.ini 中禁用 OPCache,但opcache.enable并不总是完全修复它。 To fully disable OPCache make sure all of the below settings are set要完全禁用 OPCache,请确保设置了以下所有设置

opcache.enable_cli = 0
opcache.enable     = 0

also Bitnami provides the following: Bitnami 还提供以下功能:

#Include conf/pagespeed.conf
#Include conf/pagespeed_libraries.conf

put that in your httpd.conf to be sure;)确保将其放入您的 httpd.conf 中;)

I'm done developing, how do i use OPCache to speed up performance?我已经完成了开发,如何使用 OPCache 来提高性能?

OPCache is pretty well documented on which setting does what but a general consensus has landed on the following for default settings(1) OPCache 已经很好地记录了哪个设置的作用,但普遍的共识已经落在以下默认设置上(1)

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
opcache.enable = 1

Should i use it?我应该使用它吗?

For most production cases there isn't really a reason not to, OPCache is a simple caching system that works well enough for most environments dealing with php code.对于大多数生产情况来说,没有理由不这样做,OPCache 是一个简单的缓存系统,它在大多数处理 php 代码的环境中运行良好。 If you decided to use a framework like Laravel or Symfony and many others they most likely have advised settings for your project.如果您决定使用 Laravel 或 Symfony 等框架,他们很可能会为您的项目提供建议设置。 Check to see if it's supported and if so, enable it.检查它是否受支持,如果支持,请启用它。

If you want to run anything large with many users and active connections OPCache might not be enough.如果你想运行任何有许多用户和活动连接的大型项目,那么 OPCache 可能还不够。 Like stated before, it's a pretty simple system.如前所述,这是一个非常简单的系统。

One more thing before i forget, you can clear your cache with the following php function在我忘记之前还有一件事,您可以使用以下 php function 清除缓存

opcache_reset()

sources来源

(1) https://www.php.net/manual/en/book.opcache.php (OPCache documentation) (1) https://www.php.net/manual/en/book.opcache.php (OPCache 文档)

(2) https://docs.bitnami.com/oci/infrastructure/lamp/administration/disable-cache/ (Bitnami's statement about caching) (2) https://docs.bitnami.com/oci/infrastructure/lamp/administration/disable-cache/ (Bitnami关于缓存的声明)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM