简体   繁体   中英

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.

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.

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.

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. I tried the newest one and also downgraded to 7.2.24-0 and they're the same. 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). Either way, by setting opcache.enable to 0 explicitly in the php.ini file, the behavior has stopped.

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)

2) In most browsers in the developer console when you have it open you can select to flush cache automatically.

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

Those 3 solutions should fix your issue. Mostly this kind of stuff happens with css that doesn't show the changes if you haven't cached refresh.

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. This is something Bitnami enabled(2) by default is newer versions. It's been included in PHP 5.5.0 and newer.

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. To fully disable OPCache make sure all of the below settings are set

opcache.enable_cli = 0
opcache.enable     = 0

also Bitnami provides the following:

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

put that in your httpd.conf to be sure;)

I'm done developing, how do i use OPCache to speed up performance?

OPCache is pretty well documented on which setting does what but a general consensus has landed on the following for default settings(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. If you decided to use a framework like Laravel or Symfony and many others they most likely have advised settings for your project. 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. 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

opcache_reset()

sources

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

(2) https://docs.bitnami.com/oci/infrastructure/lamp/administration/disable-cache/ (Bitnami's statement about caching)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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