使用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 条件判断标签及用 ...
随机推荐
- GITLAB安装笔记
CentOS 7 最小安装后操作 设置时区timedatectl set-timezone Asia/Shanghai 添加 Gitlab 清华源 vi /etc/yum.repos.d/gitlab ...
- Centos7安装python3并与python2共存
1.查看是否已经安装Python CentOS 7.2 默认安装了python2.7.5 因为一些命令要用它比如yum 它使用的是python2.7.5. 使用 python -V 命令查看一下是否安 ...
- POJ 2887
#include <iostream> #include <string> #define MAXN 2000 using namespace std; struct node ...
- odoo开发笔记 -- 数据库备份策略
odoo默认的数据库为postgresql数据库, PG是个非常强大的数据库,也是未来的一个趋势. 对于odoo的数据备份,odoo提供了自己的备份方式, 1. 从前台页面.输入odoo应用访问地址, ...
- VM虚拟机-Ubuntu server- 桥接模式网络配置
问题描述: 在Ubuntu虚拟机安装完毕之后,网络连接采用桥接模式,对虚拟机的eth0网卡进行静态IP设置,参数配置没有问题,但网络一直没有连接成功:即:无法实现本地主机连通虚拟机(ping不通该虚拟 ...
- Bash算术运算
使用let命令 let let let let let let let 使用expr命令 - ` # + ` # \* ` # / ` # / ` # − \* ` # +` # + -*· # -* ...
- 设置ListView显示到最后一行
上次聊天的那个界面上用的一个TextView,然后每次消息都用text.append("消息内容"+"\n")函数来在text字符串后边接一段,然后重新显示这个 ...
- php -- 数学函数
----- 016-math.php ----- <!DOCTYPE html> <html> <head> <meta http-equiv="c ...
- 移动键盘 滚动input
window.addEventListener('resize', function () { if(document.activeElement.tagName === 'INPUT'){ docu ...
- Chapter 3 Phenomenon——23
Charlie put one arm behind my back, not quite touching me, and led me to the glass doors of the exit ...