thinkphp5行为扩展实现html静态缓存设置

2018-06-19 11:53:10ThinkPHP

thnkphp5行为扩展html静态缓存

利用钩子thinkphp钩子进行行为扩展。先上本地测试结果

关闭缓存:

[email protected] */" _ue_custom_node_="true">:/home/www/wwwroot/yunshare.qq$ ab -n1000 -c10 http://yunshare.qq/Article/8/9.html

This is ApacheBench, Version 2.3

Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/

Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking yunshare.qq (be patient)

Completed 100 requests

Completed 200 requests

Completed 300 requests

Completed 400 requests

Completed 500 requests

Completed 600 requests

Completed 700 requests

Completed 800 requests

Completed 900 requests

Completed 1000 requests

Finished 1000 requests

Server Software:        nginx/1.10.0

Server Hostname:        yunshare.qq

Server Port:            80

Document Path:          /Article/8/9.html

Document Length:        67926 bytes

Concurrency Level:      10

Time taken for tests:   66.869 seconds

Complete requests:      1000

Failed requests:        0

Total transferred:      68095000 bytes

HTML transferred:       67926000 bytes

Requests per second:    14.95 [#/sec] (mean)

Time per request:       668.692 [ms] (mean)

Time per request:       66.869 [ms] (mean, across all concurrent requests)

Transfer rate:          994.46 [Kbytes/sec] received

Connection Times (ms)

min  mean[+/-sd] median   max

Connect:        0    0   0.2      0       3

Processing:   252  666  72.9    661    1066

Waiting:      252  664  72.5    659    1065

Total:        255  666  72.9    661    1066

Percentage of the requests served within a certain time (ms)

50%    661

66%    687

75%    704

80%    716

90%    757

95%    792

98%    834

99%    858

100%   1066 (longest request)

开启缓存:

[email protected] */" _ue_custom_node_="true">:/home/www/wwwroot/yunshare.qq$ ab -n1000 -c10 http://yunshare.qq/Article/8/9.html

This is ApacheBench, http://www.apache.org/

Benchmarking yunshare.qq (be patient)

Completed 100 requests

Completed 200 requests

Completed 300 requests

Completed 400 requests

Completed 500 requests

Completed 600 requests

Completed 700 requests

Completed 800 requests

Completed 900 requests

Completed 1000 requests

Finished 1000 requests

Server Software:        nginx/1.10.0

Server Hostname:        yunshare.qq

Server Port:            80

Document Path:          /Article/8/9.html

Document Length:        44835 bytes

Concurrency Level:      10

Time taken for tests:   20.578 seconds

Complete requests:      1000

Failed requests:        0

Total transferred:      45004000 bytes

HTML transferred:       44835000 bytes

Requests per second:    48.60 [#/sec] (mean)

Time per request:       205.777 [ms] (mean)

Time per request:       20.578 [ms] (mean, across all concurrent requests)

Transfer rate:          2135.77 [Kbytes/sec] received

Connection Times (ms)

min  mean[+/-sd] median   max

Connect:        0    0   0.1      0       2

Processing:    69  205  30.7    202     344

Waiting:       68  202  30.3    200     340

Total:         71  205  30.6    202     344

Percentage of the requests served within a certain time (ms)

50%    202

66%    213

75%    220

80%    224

90%    239

95%    254

98%    286

99%    328

100%    344 (longest request)

使用方法(和thinkphp3.2相似)

'配置值'

'html_cache_on' => false, // 开启静态缓存

'html_cache_time' => 7200, // 全局静态缓存有效期(秒)

'html_file_suffix' => '.shtml', // 设置静态缓存文件后缀

'html_cache_compile_type' => 'file',//缓存存储驱动

'html_cache_rules' => array( // 定义静态缓存规则

// // 定义格式1 数组方式

//'静态地址' => array('静态规则', '有效期', '附加规则'),

//1.任意控制器的任意操作都适用

'*'=>array('{$_SERVER.REQUEST_URI|md5}'),

//2.任意控制器的md5操作

'md5'=>array('{:module}/{:controller}/{:action}_{id|md5}'),

//3.Static控制器的所有操作

'Static:'=>array('{:module}/{:controller}/{:action}',50)//第一个参数是构造的字符串,后面是缓存50秒

//4.Hmtl控制器的md5操作

'Html:md5'=>array('{:module}/{:controller}/{:action}'),

)

);

参考:http://wp.iyouths.org/250.html

扩展步骤

文件位置:appplication/tags.php(或appplication/index/tags.php)

[

'appindexbehaviorReadHtmlCacheBehavior',//可自行修改文件位置

],

'view_filter' => [

'appindexbehaviorWriteHtmlCacheBehavior',

],

];

添加文件

application/index/behavior/ReadHtmlCacheBehavior.php

application/index/behavior/WriteHtmlCacheBehavior.php

注意:

检查是否修改模板文件改为了app_debug = true

php 静态扩展,thinkphp5行为扩展实现html静态缓存设置相关推荐

  1. php扩展 静态库,编译PHP扩展的方法

    [相关学习推荐:php编程(视频)] 构建PHP扩展 你已经知道如何去编译PHP本身,下一步我们将编译外部扩展.我们将讨论扩展的构建过程和可用的编译选项. 载入共享扩展 在前一个章节你已经知道,PHP ...

  2. 【Groovy】Groovy 扩展方法 ( 静态扩展方法配置 | 扩展方法示例 | 编译静态扩展类 | 打包静态扩展类字节码到 jar 包中 | 测试使用 Thread 静态扩展类 )

    文章目录 一.扩展方法示例 二.静态扩展方法配置 三.编译静态扩展类 四.打包静态扩展类字节码到 jar 包中 五.测试使用 Thread 静态扩展类 一.扩展方法示例 为 Thread 扩展 hel ...

  3. 扩展thinkphp5的redis类方法

    笔者在开发时发现,thinkphp5的自带redis类方法,只有简单的读取缓存.写入缓存的基本方法,远不能满足我们业务的需求.redis本身支持五种数据类型,string(字符串).hash(哈希). ...

  4. compser可以检查php扩展吗,composer扩展

    ## 一些简单的thinkphp扩展 1. 正则表达式的扩展: PHP7以上: ``` composer req gherkins/regexpbuilderphp ``` PHP5 ``` comp ...

  5. 【Groovy】Groovy 扩展方法 ( 扩展静态方法示例 | 扩展实例方法示例 | 扩展实例方法与扩展静态方法代码相同 )

    文章目录 一.扩展静态方法示例 二.扩展实例方法示例 三.扩展实例方法与扩展静态方法代码相同 一.扩展静态方法示例 在上一篇博客 [Groovy]Groovy 扩展方法 ( Groovy 扩展方法引入 ...

  6. 【Groovy】Groovy 扩展方法 ( Groovy 扩展方法引入 | 分析 Groovy 中 Thread 类的 start 扩展方法 )

    文章目录 一.Groovy 扩展方法引入 二. 分析 Groovy 中 Thread 类的 start 扩展方法 一.Groovy 扩展方法引入 Groovy 可以对 JDK 中的一些类进行 方法扩展 ...

  7. 字扩展,位扩展,和字位扩展_价格合理,可扩展的网站简介

    字扩展,位扩展,和字位扩展 One morning you wake up, grab some coffee, and check the how many people visited your ...

  8. 数据库水平扩展和垂直扩展

    原地址:https://www.cnblogs.com/blfshiye/p/5059748.html https://www.2cto.com/database/201607/524821.html ...

  9. kotlin - 扩展方法和扩展属性

    kotlin - 扩展方法和扩展属性 我们都知道java要扩展一个已有类的方法和属性必须采用继承.组合或直接修改现有类来进行功能和属性的扩展.而kotlin是完全支持扩展方法和扩展属性的,这样我们就可 ...

最新文章

  1. 三菱fx2n64mr说明书_三菱FX2N可编程控制器使用手册
  2. 【Codeforces】1065B Vasya and Isolated Vertices (无向图的)
  3. 学计算机一般要off,必须要学的电脑知识
  4. Eclipse的JQuery提示插件-Spket(别试了,没什么效果,且安装设置麻烦)
  5. 面试题目--MPEG4与H.264的区别
  6. [mysql] mysql-myibatis-整理
  7. 01背包及其变种(物品无限背包、恰好装满背包)
  8. LAMP 2.2 Apache配置静态缓存
  9. 我们这旮都是黑社会[转]
  10. Opencv与dlib联合进行人脸关键点检测与识别
  11. FreeMarker字符串操作
  12. 2.8 复习 定语从句 将来进行时 将来完成时
  13. 虚拟机的三种网络连接方式
  14. 加权有限状态转录机(Weighted Finite-State Transducer/WFST)
  15. NotebookApp] 302 GET /?token=be0e8107dd84eab831a957b640602e5157b5336b15e7fa61 (127.0.0.1) 1.000000ms
  16. [风一样的创作]二次封装阿里云短信 验证码 发送短信 查询短信 编辑短信
  17. 吴穹:金融行业已来到全面推行数字化研发管理的时点
  18. [JS权威指南笔记] 第1章-第3章
  19. Fiddler 进行接口测试
  20. 微信小程序 使用.wxs在.wxml中分割字符串渲染多条数据

热门文章

  1. Video Game Troubles(有依赖的背包)
  2. 【ESSD技术解读】 云原生时代,阿里云块存储 ESSD 快照服务如何被企业级数据保护所集成?
  3. 李飞飞演讲实录 | 云原生数据库2.0:一站式全链路数据管理与服务
  4. 如何选择物联网软件开发供应商
  5. 在阿里,我们如何管理代码分支?
  6. AI时代的神马搜索!神马智能对话技术深度解读
  7. 由浅到浅入门批量渲染(三)
  8. 美术师关于自己的报酬与工作的看法
  9. 数据库面试题【五、索引的优缺点,什么时候使用索引,什么时候不能使用索引】
  10. AIX-maxuproc参数案例