duangeli1334 2019-04-28 13:00
浏览 105

尽管进行了彻底的设置和调整,但无法禁用PHP缓存

Happy Sunday,

I am struggling and hair pulling for 3 days (fearing being almost bold by the end of the month) about the cache management on a Bitnami lamp-packaged instance running on Azure on Ubuntu 16.x.

I am engaged in a PHP5 to PHP7 migration of a big system since several weeks, about to complete the task.

My test site using the system can be reached here: https://stephanedeluca.com for you to look at the cache.

Unfortunately, what I see, is that my PHP scripts are not immediately reflecting the changes I make once deployed (simple upload) to the server. And as a consequences, the UX is sometime destroyed by the fact the user often needs to double refresh, and in the worst cases, have to reload everything via the browser.

On the previous system, everything was good, but on this new box, I've got the issue. The box uses php-fpm.

What I achieved so far regarding the resolution of the cache management:

  • from php.ini, I disabled the OPCache; — from the .htaccess, I have used mod_expires (I also installed mod_headers and mod_expires) as follows:

    <ifModule mod_expires.c>
        ExpiresActive On
        ExpiresDefault "access plus 0 seconds"
    </ifModule>
    <FilesMatch "\.(flv|ico|pdf|avi|mov|ppt|doc|mp3|wmv|wav)$">
        <ifModule mod_expires.c>
            ExpiresDefault "access plus 1 years"
        </ifModule>
        <ifModule mod_headers.c>
            #Header append Cache-Control "public"
        </ifModule>
    </FilesMatch>
    <FilesMatch "\.(gif|jpg|jpeg|png)$">
        <ifModule mod_expires.c>
            ExpiresDefault "access plus 1 weeks"
        </ifModule>
        <ifModule mod_headers.c>
            #Header append Cache-Control "public"
        </ifModule>
    </FilesMatch>    
    <FilesMatch "\.(xml|json|txt|html|js|css)$">
        <ifModule mod_expires.c>
            ExpiresDefault "access plus 2 hours"
        </ifModule>
        <ifModule mod_headers.c>
            #Header append Cache-Control "proxy-revalidate"
        </ifModule>
    </FilesMatch>
    <filesMatch "\.(php)$">
        FileETag None
        <ifModule mod_headers.c>
            Header unset ETag
            #Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate"
            Header set Pragma "no-cache"
            #Header set Expires "Tue, 15 Mar 1966 10:00:00 GMT+1"
        </ifModule>
    </filesMatch>
    
  • all my PHP scripts (via prepend) generate the following headers (right after session_start() is invoked):

    // === No caching ===
    session_cache_limiter('private');
    session_cache_expire(0);
    
    // === Start session (must be after session_cache_X())
    session_start();
    
    header('Cache-Control: private, max-age=0, s-max-age=0, no-cache, no-store, must-revalidate', true);
    header("Last-Modified: $headerNow", true);
    

While looking at the browser request and response, I see that everything looks good imho:

Request (as reported by Chrome)

Request URL: https://stephanedeluca.com/
Request Method: GET
Status Code: 200 OK (from ServiceWorker)
Referrer Policy: no-referrer-when-downgrade

Response:

Cache-Control: private, max-age=0, s-max-age=0, no-cache, no-store, must-revalidate
Connection: Keep-Alive
Content-Encoding: gzip
Content-Type: text/html; charset=UTF-8
Date: Sun, 28 Apr 2019 12:36:57 GMT
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Keep-Alive: timeout=5, max=100
Last-Modified: Sun, 28 Apr 2019 12:36:57 GMT
Pragma: no-cache
Server: Apache
Transfer-Encoding: chunked
Vary: Accept-Encoding
X-Frame-Options: SAMEORIGIN
X-Generated-On: Sun, 28 Apr 2019 12:36:57 GMT
X-Powered-By: ZID/Webengine v24.0b27 -- Copyright (c) 1995-2019 MagicApps (http://MgcApps.com) -- All Rights Reserved
Provisional headers are shown
Referer: https://stephanedeluca.com/map.php
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36

I've also checked the cache by using https://www.giftofspeed.com/cache-checker/ and the report is as expected.

I am running out of ideas.

  • 写回答

1条回答 默认 最新

  • doutu6658 2019-04-30 09:40
    关注

    Bitnami Engineer here. In order to disable the cache in the server and let the files be served each time, disable PageSpeed for Apache and OPCache for PHP, enabled by default.

    To disable PageSpeed, comment out the following lines in your httpd.conf (/opt/bitnami/apache2/conf/httpd.conf)

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

    To disable OPCache, change opcache.enable in your php.ini file and set it to 0 (/opt/bitnami/php/etc/php.ini)

    Restart all the services after that

    sudo /opt/bitnami/ctlscript.sh restart
    
    评论

报告相同问题?

悬赏问题

  • ¥20 求数据集和代码#有偿答复
  • ¥15 关于下拉菜单选项关联的问题
  • ¥20 java-OJ-健康体检
  • ¥15 rs485的上拉下拉,不会对a-b<-200mv有影响吗,就是接受时,对判断逻辑0有影响吗
  • ¥15 使用phpstudy在云服务器上搭建个人网站
  • ¥15 应该如何判断含间隙的曲柄摇杆机构,轴与轴承是否发生了碰撞?
  • ¥15 vue3+express部署到nginx
  • ¥20 搭建pt1000三线制高精度测温电路
  • ¥15 使用Jdk8自带的算法,和Jdk11自带的加密结果会一样吗,不一样的话有什么解决方案,Jdk不能升级的情况
  • ¥15 画两个图 python或R