php - 尽管进行了彻底的设置和调整,但仍无法禁用 PHP 缓存
问题描述
快乐星期天,
关于在 Ubuntu 16.x 上运行在 Azure 上的 Bitnami 灯封装实例上的缓存管理,我苦苦挣扎了 3 天(担心到月底几乎是大胆的)。
我在搞一个PHP5到PHP7的一个大系统迁移几个星期了,即将完成任务。
我使用该系统的测试站点可以在这里访问:https ://stephanedeluca.com供您查看缓存。
不幸的是,我看到的是,我的 PHP 脚本并没有立即反映我在部署(简单上传)到服务器后所做的更改。因此,UX 有时会因为用户经常需要双重刷新而破坏,在最坏的情况下,必须通过浏览器重新加载所有内容。
在以前的系统上,一切都很好,但是在这个新盒子上,我遇到了问题。该框使用php-fpm。
到目前为止,我在解决缓存管理方面取得的成就:
从 php.ini,我禁用了 OPCache;— 从 开始
.htaccess
,我使用了 mod_expires(我还安装了 mod_headers 和 mod_expires),如下所示:<ifModule mod_expires.c> 过期活动在 ExpiresDefault "访问加 0 秒" </ifModule> <FilesMatch "\.(flv|ico|pdf|avi|mov|ppt|doc|mp3|wmv|wav)$"> <ifModule mod_expires.c> ExpiresDefault "访问加 1 年" </ifModule> <ifModule mod_headers.c> #Header 附加缓存控制“公共” </ifModule> </文件匹配> <文件匹配 "\.(gif|jpg|jpeg|png)$"> <ifModule mod_expires.c> ExpiresDefault "访问加 1 周" </ifModule> <ifModule mod_headers.c> #Header 附加缓存控制“公共” </ifModule> </文件匹配> <FilesMatch "\.(xml|json|txt|html|js|css)$"> <ifModule mod_expires.c> ExpiresDefault "访问加 2 小时" </ifModule> <ifModule mod_headers.c> #Header 附加缓存控制“代理重新验证” </ifModule> </文件匹配> <filesMatch "\.(php)$"> FileETag 无 <ifModule mod_headers.c> 标头未设置 ETag #Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate" 标头集 Pragma "no-cache" #标头集过期“1966 年 3 月 15 日星期二 10:00:00 GMT+1” </ifModule> </filesMatch>
我所有的 PHP 脚本(通过 prepend)生成以下标头(在 session_start() 被调用之后):
// === 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);
在查看浏览器请求和响应时,我看到一切看起来都很好恕我直言:
请求(由 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/检查了缓存,报告符合预期。
我的想法不多了。
解决方案
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
推荐阅读
- reactjs - 如何将我的“输入”控件中的属性公开给任何其他组件?
- java - 这是同步代码块的安全方法吗?
- php - localhost/phpmyadmin 返回一些原始 php 代码而不是登录页面
- python - 尝试从 Google Cloud Firestore 检索所有文档时如何处理超时错误?
- excel - 多个如果为空参数的公式
- php - PHP会话cookie在页面刷新时重置
- imagej - ImageJ 宏帮助:根据文件名不同地处理图像
- google-apps-script - 打开时自动更新谷歌幻灯片中的所有链接对象
- amazon-web-services - 我如何使用 AWS texttract API 获取 OCR PDF 布局..?
- linux - Killing subprocess from inside a Docker container kills the entire container