首页 > 解决方案 > 尽管进行了彻底的设置和调整,但仍无法禁用 PHP 缓存

问题描述

快乐星期天,

关于在 Ubuntu 16.x 上运行在 Azure 上的 Bitnami 灯封装实例上的缓存管理,我苦苦挣扎了 3 天(担心到月底几乎是大胆的)。

我在搞一个PHP5到PHP7的一个大系统迁移几个星期了,即将完成任务。

我使用该系统的测试站点可以在这里访问:https ://stephanedeluca.com供您查看缓存。

不幸的是,我看到的是,我的 PHP 脚本并没有立即反映我在部署(简单上传)到服务器后所做的更改。因此,UX 有时会因为用户经常需要双重刷新而破坏,在最坏的情况下,必须通过浏览器重新加载所有内容。

在以前的系统上,一切都很好,但是在这个新盒子上,我遇到了问题。该框使用php-fpm。

到目前为止,我在解决缓存管理方面取得的成就:

在查看浏览器请求和响应时,我看到一切看起来都很好恕我直言:

请求(由 Chrome 报告)

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

回复:

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

我还使用https://www.giftofspeed.com/cache-checker/检查了缓存,报告符合预期。

我的想法不多了。

标签: phpbrowser-cachephp-7bitnami

解决方案


Bitnami 工程师在这里。为了禁用服务器中的缓存并让文件每次都被提供,请禁用 Apache 的 PageSpeed 和 PHP 的 OPCache,默认启用。

要禁用 PageSpeed,请在 httpd.conf (/opt/bitnami/apache2/conf/httpd.conf) 中注释掉以下行

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

要禁用 OPCache,请更改 php.ini 文件中的 opcache.enable 并将其设置为 0 (/opt/bitnami/php/etc/php.ini)

之后重启所有服务

sudo /opt/bitnami/ctlscript.sh restart

推荐阅读