index-with-redis.php,wordpress 启用redis缓存功能

版本信息:nginx / wordpress 4.x / php7

参考文章:https://www.freehao123.com/redis-wordpress/

2,用Predis.php作为Redis的PHP客户端

直接将Predis.php下载并上传到Wordpress的根目录下并给以nginx权限

wget https://www.jinchuang.org/novel/doc/predis.php_file

mv predis.php_file predis.php

chown nginx:nginx predis.php

在predis.php 文件中修改你的redis连接信息

65e0b42d7943e20752a4a68e1e5d2d48.png

3,安装Redis前端缓存的PHP脚本

wget https://www.jinchuang.org/novel/doc/index-with-redis.php_file

mv index-with-redis.php_file index-with-redis.php

备份原来的index.php文件

mv index.php index.php.bak

重命名刚下载的文件为index.php //这个脚本我也下载别人的使用后不产生缓存,修改了下可以缓存但是清缓存没有用就用脚本定时执行清除redis缓存。

mv index-with-redis.php_file index.php

4,打开查看redis 的index-with-redis.php的Debug ,可以在页面下方看到访问的时间。值修改为 1 为显示,0 为不显示 。

77521e7bb0a4fe463d920dacf4a5c4a5.png

45cdef1de312703c4f5e60f4fed10225.png

f9ef3c08469fc5d77ee57475eb850259.png

13aee710c00760ddc9b76440f556ecee.png

查看服务器redis 是否有产生缓存:

连到你的redis中 :

keys *              #查看缓存命令

521c5ab17396b1dd4fc5f2747d7912fd.png

5.优化版本[直接用这个]

功能差不多,主要有:登录时页面不缓存、除非删除或者重置否则不删除缓存页面、登录时在任意URL后加上?c=y可以删除整个网站缓存、在任意URL后面加上?c=y可以清除此URL缓存、allow_fopen被禁止也可以正常运行、发表评论时删除该页面缓存。

下载地址:https://www.jinchuang.org/novel/doc/index-optimization-redis

6,Wordpress删除Redis页面缓存的方法

删除某一个页面的缓存:发表评论、按下F5刷新、在URL后面加上?r=y回车。

删除整站页面缓存:登录到Wordpress后台,在任意URL后面加上?r=y回车。

更新文章时自动刷新首页缓存:在你的Wordpress的Function.php中加入以下代码(出自:https://blog.zts1993.com/4738.html):

function newPostRefresh() {

$temp=file_get_contents(“https://xxxxxxx/?r=y”); //xxxxxx自己替换

}

add_action(‘publish_post’, ‘newPostRefresh’);

add_action(‘edit_post’, ‘newPostRefresh’);

add_action(‘delete_post’, ‘newPostRefresh’);

add_action(‘comment_post’, ‘newPostRefresh’);

add_action(‘edit_comment’, ‘newPostRefresh’);

add_action(‘delete_comment’, ‘newPostRefresh’);

add_action(‘wp_set_comment_status’, ‘newPostRefresh’);

add_action(‘switch_theme’, ‘newPostRefresh’);

自动更新Wordpress缓存:在crontab中配置每10分钟用curl访问首页更新缓存,每天凌晨对首页或者分类目录页面进行更新。

*/10 * * * * curl https://blog.jinchuang.org/?r=y

1 1 * * * curl https://blog.jinchuang.org/category/technology/?r=y

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值