memcache提速wordpress
虚拟机安装memcache缓存 提速wordpress
但是如果主机内存 小于 512M 还是别这样做
全站静态还好一些 我用的内存1025M
wordpress5.3.2 php 5.6
主题 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 );
安装memcached服务端
ps -ef | grep memcached
grep memcached
/usr/local/memcached/bin/memcached -d -l 127.0.0.1 -p 11211 -u root -m 64 -c 1024 -P /var/run/memcached.pid
安装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
下载wordpress memcache插件
wget https://downloads.wordpress.org/plugin/memcached.3.0.1.zip
把object-cache.php解压到wp-content目录下 命令ls 查看
index.php languages object-cache.php package.xml plugins themes upgrade uploads
比较 安装 memcache缓存的版本 首页性能
3 queries in 0.451 seconds, using 13.56MB memory
没有启用缓存的系统 首页性能
16 queries in 1.336 seconds, using 12.98MB memory
可以看见有很明显的提升 其他页面都会被优化 缓存到
尊贵的董事大人
英文标题不为空时 视为本栏投稿
需要关键字 描述 英文标题