使用memcache对wordpress优化,提速
环境:
一个本地开发环境
一个部署在虚拟机中( 虚拟机安装memcache缓存),然后用这个优化的版本跟本地开发环境对比.
wordpress版本:4.9.5
php:5.6版本
1,首先在主题的functions.php文件中,加入以下监控统计代码
function performance( $visible = true ) {
$stat = sprintf( '%d queries in %.3f seconds, using %.2fMB memory',
get_num_queries(),
timer_stop( 0, 3 ),
memory_get_peak_usage() / 1024 / 1024
);
// echo $visible ? $stat : "<!-- {$stat} -->" ;
echo "<div class='container_12'><p class='grid_12 footer clearfix'>$stat</p></div>";
}
add_action( 'wp_footer', 'performance', 20 );
样式可以根据自己的主题定制,这段代码可以统计出页面有多少次数据库查询。总共花了多少秒,耗费多少内存,类似如下的样式:
16 queries in 1.306 seconds, using 12.98MB memory
2,安装memcached服务端
[root@bogon wp-content]# ps -ef | grep memcached
root : pts/ :: grep memcached
root : ? :: /usr/local/memcached/bin/memcached -d -l 127.0.0.1 -p -u root -m -c -P /var/run/memcached.pid
3,安装php memcache扩展
wget http://pecl.php.net/get/memcache-3.0.8.tgz,用phpize外挂方式安装,安装完成之后,在php.ini中启用,再重启php,确定memcache已经加载
memcache
memcache support enabled
Version 3.0.8
Revision $Revision: 329835 $
Directive Local Value Master Value
memcache.allow_failover 1 1
memcache.chunk_size 32768 32768
memcache.compress_threshold 20000 20000
memcache.default_port 11211 11211
memcache.hash_function crc32 crc32
memcache.hash_strategy consistent consistent
memcache.lock_timeout 15 15
memcache.max_failover_attempts 20 20
memcache.protocol ascii ascii
memcache.redundancy 1 1
4,下载wordpress memcache插件
wget https://downloads.wordpress.org/plugin/memcached.3.0.1.zip
把object-cache.php解压到wp-content目录下
[root@bogon wp-content]# ls
index.php languages object-cache.php package.xml plugins themes upgrade uploads
[root@bogon wp-content]#
最后比较服务器
安装了memcache缓存的版本,首页性能:
queries in 0.451 seconds, using .56MB memory
没有启用缓存的系统,首页性能:
queries in 1.336 seconds, using .98MB memory
可以看见有很明显的提升,其他页面都会被优化,缓存到
启用opcache,再次提速:
queries in 0.129 seconds, using .48MB memory
php.ini中opcache需要这样加载:
zend_extension=opcache.so
opcache相关配置:
[opcache]
; Determines if Zend OPCache is enabled
opcache.enable= ; Determines if Zend OPCache is enabled for the CLI version of PHP
opcache.enable_cli= ; The OPcache shared memory storage size.
opcache.memory_consumption= ; The amount of memory for interned strings in Mbytes.
opcache.interned_strings_buffer= ; The maximum number of keys (scripts) in the OPcache hash table.
; Only numbers between and are allowed.
opcache.max_accelerated_files= ; The maximum percentage of "wasted" memory until a restart is scheduled.
;opcache.max_wasted_percentage=
"php.ini" 2051L, 74201C written [ldap]
; Sets the maximum number of open links or - for unlimited.
ldap.max_links = - [mcrypt]
; For more information about mcrypt settings see http://php.net/mcrypt-module-open ; Directory where to load mcrypt algorithms
; Default: Compiled in into libmcrypt (usually /usr/local/lib/libmcrypt)
;mcrypt.algorithms_dir= ; Directory where to load mcrypt modes
; Default: Compiled in into libmcrypt (usually /usr/local/lib/libmcrypt)
;mcrypt.modes_dir= [dba]
;dba.default_handler= [opcache]
; Determines if Zend OPCache is enabled
opcache.enable= ; Determines if Zend OPCache is enabled for the CLI version of PHP
opcache.enable_cli= ; The OPcache shared memory storage size.
opcache.memory_consumption= ; The amount of memory for interned strings in Mbytes.
opcache.interned_strings_buffer= ; The maximum number of keys (scripts) in the OPcache hash table.
; Only numbers between and are allowed.
opcache.max_accelerated_files=
使用memcache对wordpress优化,提速的更多相关文章
- wordpress优化:Gravatar头像被墙及解决方案
网站缓存现象: 打开网站是左下角出现0.gravatar.com.1.gravatar.com或2.gravatar.com字样,网站一直处于缓存状态,迟迟未能打开.很多人都会缺乏耐心地等待一个网页的 ...
- 关于web系统整体优化提速总结
关于web系统整体优化提速总结 一.背景 随着公司业务的拓展,随之而来就是各种系统横向和纵向的增加,PV.UV也都随之增加,原有的系统架构和模式慢慢遇上了瓶颈,需要逐步的对系统从整体上进行改造升级,通 ...
- sql优化提速整理
sql优化提速整理 场景描述 在我们实际开发中,随着业务的不断增加,数据量也在不断的攀升,这样就离不开一个问题:数据查询效率优化 根据自己的以往实际项目工作经验和学习所知,现在对SQL查询优化做一个简 ...
- wordpress优化之结合prism.js为编辑器自定义按钮转化代码
原文链接 http://ymblog.net/2016/07/24/wordpress-prism/ 继昨天花了一天一夜的时间匆匆写了主题Jiameil3.0之后,心中一直在想着优化加速,体验更好,插 ...
- 记录一次读取memcache缓存的优化
我们是用mvc做web,大部分数据都用memcache做了缓存 有2台memcache缓存服务器 数据并不大. 某页面响应较慢,大概在4s左右. 页面本身很简单只是显示一个表单. 但是layout相对 ...
- eclipse 优化提速
1.windows–>perferences–>general–>startup and shutdown关掉没用的启动项: WTP :一个跟myeclipse差不多的东西,主要差别 ...
- windows 10 超级优化提速 附系统服务列表纯净
如图,本机安装了vs2017 office2016 迅雷.谷歌浏览器,不建议安装其它任何软件.vs2017为开发软件,用于编程,一般用户用不到. 如果想安装其它的软件,建议优先使用绿色版本的. 下载服 ...
- 通过URLOS安装Redis缓存为wordpress网站提速
快!快!快!我们都知道网站的加载速度直接影响用户体验.据研究发现,网站页面在3秒内加载完毕对用户而言是最佳的浏览体验.如果超过这个时间,用户跳出网站的几率会非常大.所以对于站长来说,提高速度是他们追求 ...
- Wordpress学习链接整理
Wordpress学习链接整理 获取和使用 WordPress 中的全局变量 wordpress模板加载顺序汇总 WordPress载入页面时的模板加载机制(图) WordPress 条件判断标签及用 ...
随机推荐
- pyqt5 Button.click 报错:argument 1 has unexpected type 'NoneType'
如上所示,在括号中,添加‘lambda:’,就可以成功运行,不知道为啥. 参考:https://blog.csdn.net/flhsxyz/article/details/79220936?utm_s ...
- CentOS 7修改yum源为阿里源
1.备份本地源 1 # mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo_bak 2.获取阿里yum源配置 ...
- sublime text syntaxdef
http://sublimetext.info/docs/en/extensibility/syntaxdefs.html
- 【翻译】 Windows 内核漏洞学习—空指针解引用
Windows Kernel Exploitation – NullPointer Dereference 原文地址:https://osandamalith.com/2017/06/22/windo ...
- Swift 里 Array (二)初始化
init() 函数 在 Array 里 public init() { _buffer = _Buffer() } 以Buffer 是 _ContiguousArrayBuffer 为例. 即初始化了 ...
- Android初识Helloworld
在Eclipse+ADT中创建HelloWorld非常简单,直接按照导航下一步就可以了.本文重点不在如何创建,而在理解HelloWorld项目的文件. HelloWorld的目录结构有: src:存放 ...
- Identity Server4学习系列四之用户名密码获得访问令牌
1.简介 Identity Server4支持用户名密码模式,允许调用客户端使用用户名密码来获得访问Api资源(遵循Auth 2.0协议)的Access Token,MS可能考虑兼容老的系统,实现了这 ...
- 全网最详细的Hadoop HA集群启动后,两个namenode都是active的解决办法(图文详解)
不多说,直接上干货! 这个问题,跟 全网最详细的Hadoop HA集群启动后,两个namenode都是standby的解决办法(图文详解) 是大同小异. 欢迎大家,加入我的微信公众号:大数据躺过的坑 ...
- 轻量级web富文本框——wangEditor使用手册(4)——配置下拉菜单 demo
最新版wangEditor: 配置说明:http://www.wangeditor.com/doc.html demo演示:http://www.wangeditor.com/wangEditor/d ...
- sql-DDL, DML 常用语句
mysql的安装可见: http://www.cnblogs.com/wenbronk/p/6840484.html 很久不用mysql, 今天建表都不会了, , , 慢慢补充 sql语言分为3种: ...