您现在的位置是:首页 > cms教程 > WordPress教程WordPress教程
memcache对wordpress优化提速步骤
幼翠2025-03-28WordPress教程已有人查阅
导读一个本地开发环境一个部署在虚拟机中( 虚拟机安装memcache缓存),然后用这个优化的版本跟本地开发环境对比.wordpress版本:4.9.5php:5.6版本1,首先在主题的functions.php文件
一个本地开发环境
一个部署在虚拟机中( 虚拟机安装memcache缓存),然后用这个优化的版本跟本地开发环境对比.
wordpress版本:4.9.5
php:5.6版本
1,首先在主题的functions.php文件中,加入以下监控统计代码
16 queries in 1.306 seconds, using 12.98MB memory
2,安装memcached服务端
wget http://pecl.php.net/get/memcache-3.0.8.tgz,用phpize外挂方式安装,安装完成之后,在php.ini中启用,再重启php,确定memcache已经加载
wget https://downloads.wordpress.org/plugin/memcached.3.0.1.zip
把object-cache.php解压到wp-content目录下
安装了memcache缓存的版本,首页性能:
3 queries in 0.451 seconds, using 13.56MB memory
没有启用缓存的系统,首页性能:
16 queries in 1.336 seconds, using 12.98MB memory
可以看见有很明显的提升,其他页面都会被优化,缓存到
启用opcache,再次提速:
3 queries in 0.129 seconds, using 3.48MB memory
php.ini中opcache需要这样加载:
zend_extension=opcache.so
opcache相关配置:
一个部署在虚拟机中( 虚拟机安装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 5050 3466 0 14:44 pts/1 00:00:00 grep memcached
root 29269 1 0 13:57 ? 00:00:02 /usr/local/memcached/bin/memcached -d -l 127.0.0.1 -p 11211 -u root -m 64 -c 1024 -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缓存的版本,首页性能:
3 queries in 0.451 seconds, using 13.56MB memory
没有启用缓存的系统,首页性能:
16 queries in 1.336 seconds, using 12.98MB memory
可以看见有很明显的提升,其他页面都会被优化,缓存到
启用opcache,再次提速:
3 queries in 0.129 seconds, using 3.48MB memory
php.ini中opcache需要这样加载:
zend_extension=opcache.so
opcache相关配置:
[opcache]
; Determines if Zend OPCache is enabled
opcache.enable=1
; Determines if Zend OPCache is enabled for the CLI version of PHP
opcache.enable_cli=1
; The OPcache shared memory storage size.
opcache.memory_consumption=528
; The amount of memory for interned strings in Mbytes.
opcache.interned_strings_buffer=8
; The maximum number of keys (scripts) in the OPcache hash table.
; Only numbers between 200 and 100000 are allowed.
opcache.max_accelerated_files=10000
; The maximum percentage of "wasted" memory until a restart is scheduled.
;opcache.max_wasted_percentage=5
"php.ini" 2051L, 74201C written
[ldap]
; Sets the maximum number of open links or -1 for unlimited.
ldap.max_links = -1
[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=1
; Determines if Zend OPCache is enabled for the CLI version of PHP
opcache.enable_cli=1
; The OPcache shared memory storage size.
opcache.memory_consumption=528
; The amount of memory for interned strings in Mbytes.
opcache.interned_strings_buffer=8
; The maximum number of keys (scripts) in the OPcache hash table.
; Only numbers between 200 and 100000 are allowed.
opcache.max_accelerated_files=10000
本文标签:
很赞哦! ()
相关教程
图文教程
wordpress后台登陆地址怎么修改
wordpress博客后台登陆地址默认的是,这个后台中没有修改项,只能靠我们自己了。为了安全这个还是一定要改掉后台路径的。下面为大家分享下修改后台路径的方法。
wordpress支持html吗,wordpress怎么支持html
wordpress不能直接支持html,需要将xx.html修改为page-xx.php上传到你当前使用的主题目录中使用
wordpress主题模版怎么去除版权,wordpress主题版权怎么删除
1、打开主题文件夹:wp-content/themes/主题名称/footer.php;3、删除这段代码即可,删除后会什么都不显示,这样不是很美观,可己添加下自己的版权信息,可以替换为以下代码:
wordpress去除底部链接的方法
使用Wordpress的一些默认主题的时候,在页面的底部会显示“自豪地采用WordPress”链接,如果你不喜欢这些内容,在底部的模板代码footer.php里删除字样就好了
相关源码
-
宽屏自适应搬家家政快递物流公司网站模板该宽屏大气的响应式网站模板专为搬家公司、家政服务及物流快递企业设计,基于PbootCMS内核开发,通过自适应布局确保手机、PC等多终端体验一致,助力企业高效构建专业在线服务平台。查看源码 -
pbootcms模板(PC+WAP)火锅加盟餐饮美食类带留言源码基于PbootCMS内核深度开发,为火锅、餐饮品牌打造的营销型解决方案。采用红色主题传递行业活力,实现PC与WAP端适配。查看源码 -
(PC+WAP)pbootcms模板黑色门窗定制五金建材网站下载为门窗定制与五金建材企业设计的网站解决方案,采用PbootCMS开发,兼具专业展示与营销功能。黑色系设计突显工业质感,响应式布局确保在手机、平板等设备上的浏览体验。通过简单的内容替换,也可适用于建材贸易、家具定制等相关行业。查看源码 -
(自适应)变压器电子元器件电器配件pbootcms网站模板源码为电子元器件企业打造的响应式网站模板,基于PbootCMS内核开发,助力企业快速构建专业级线上展示平台。支持页面独立设置标题、关键词和描述,内置SEO友好结构。PHP程序确保运行安全稳定,有助于提升搜索引擎收录效果。查看源码 -
粉色家政月嫂保姆公司pbootcms网站模板(PC+WAP)为家政服务、月嫂保姆企业打造的营销型解决方案,基于PbootCMS内核开发,采用温馨粉色主题传递行业温度。PHP7.0+高性能架构支持SQLite/MySQL双数据库查看源码 -
(自适应)刷卡pos机数据移动支付设备电子科技pbootcms模板下载本模板为POS机设备制造商、移动支付终端服务商和科技企业设计,基于PbootCMS系统开发,提供完整的在线展示平台解决方案,满足支付设备行业特有的展示需求。查看源码
| 分享笔记 (共有 篇笔记) |

