socalnick/scn-http-cache
Composer 安装命令:
composer require socalnick/scn-http-cache
包简介
Adds several features to help make ZF2 applications cacheable.
README 文档
README
A ZF2 module that helps implement standards based caching built into the HTTP spec and gateway caches.
Requirements
- Zend Framework 2 (2.*)
Features
- PHP implementation of a gateway cache (COMING SOON)
- Plugin for manipulating HTTP Cache headers (COMING SOON)
- Plugin for dealing with expiration and validation (COMING SOON)
- ESI View Helper
- Very performant in Surrogate Capability mode - just renders ESI tag
- Works w/o surrogate capability by running separate application lifecycle
Installation
It is recommended to add this module to your Zend Framework 2 application using Composer. After cloning ZendSkeletonApplication, add "socalnick/scn-http-cache" to list of requirements, then run php composer.phar install/update. Your composer.json should look something like this:
{
"name": "zendframework/skeleton-application",
"description": "Skeleton Application for ZF2",
"license": "BSD-3-Clause",
"keywords": [
"framework",
"zf2"
],
"homepage": "http://framework.zend.com/",
"require": {
"php": ">=5.3.3",
"zendframework/zendframework": "2.*",
"socalnick/scn-http-cache": "1.*"
}
}
Next add the required modules to config/application.config.php:
<?php return array( 'modules' => array( 'Application', 'ScnHttpCache', ), 'module_listener_options' => array( 'config_glob_paths' => array( 'config/autoload/{,*.}{global,local}.php', ), 'module_paths' => array( './module', './vendor', ), ), );
Varnish
Installation
Varnish can be installed on any modern Linux distribution: https://www.varnish-cache.org/docs/3.0/installation/ It is also available via Homebrew on Mac OSX for development by running brew install varnish
Configuration
This is the most basic Varnish configuration for a development environment. It sets the backend host / port, sets a request header indicating Surrogate Capability, and looks for the response Surrogate Control header to initiate ESI handling. Before running Varnish in a production environment, I highly encourage you to learn more about it at https://www.varnish-cache.org/docs
backend default {
.host = "127.0.0.1";
.port = "10088";
}
sub vcl_recv {
# Set a header announcing Surrogate Capability to the origin
# ScnEsiWidget sees this header and emits ESI tag for widgets
set req.http.Surrogate-Capability = "varnish=ESI/1.0";
}
sub vcl_fetch {
# Unset the Surrogate Control header and do ESI
if (beresp.http.Surrogate-Control ~ "ESI/1.0") {
unset beresp.http.Surrogate-Control;
set beresp.do_esi = true;
}
}
Usage
Echo ESI in View Script
<div><?php echo $this->esi($this->url('route/to/recent/tweets')) ?></div>
Make the ESI Action
public function recentTweetsAction() { $headers = $this->getResponse()->getHeaders(); $cacheControl = new \Zend\Http\Header\CacheControl(); $cacheControl->addDirective('s-maxage', '10'); $headers->addHeader($cacheControl); $viewModel = new ViewModel(); $viewModel->setTerminal(true); return $viewModel; }
Make a View Script for ESI Widget Action
<ul>
<li><?php echo date('h:i:s')?> @SocalNick: This is a recent tweet!</li>
<li><?php echo date('h:i:s', time() - 10)?> @SocalNick: This is a slightly less recent tweet!</li>
</ul>
socalnick/scn-http-cache 适用场景与选型建议
socalnick/scn-http-cache 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 11.13k 次下载、GitHub Stars 达 8, 最近一次更新时间为 2013 年 02 月 05 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「esi」 「zf2」 「varnish」 「edge side includes」 「cache-control」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 socalnick/scn-http-cache 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 socalnick/scn-http-cache 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 socalnick/scn-http-cache 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
LosLog provides some log utility
Varnish cache bundle for Symfony 2
EdpModuleLayouts is very simple Laminas module for making module-specific layouts insanely easy.
Render content in fusion as esi:include
Speed up your TYPO3 installation: add Critical CSS (Above The Fold) inline, minify the HTML of your website, use subdomains as CDN to reduce page load, manage proxy-caching (e.g with Varnish) via page-properties.
A standalone ESI (Eve Swagger Interface) Client Library using kevinrob/guzzle-cache-middleware
统计信息
- 总下载量: 11.13k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 9
- 点击次数: 20
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: BSD-3-Clause
- 更新时间: 2013-02-05