Discuz!中增加memcache缓存的方法

很多站长都有体会,随着坛子越来越大,链接超时的问题越来越严峻。

google后并尝试用这里说的方法来做优化。但发现不够。被缓存的帖子不会在修改或者删除后自动清空缓存。当存在附件的帖子有权限和无权限的人看到的效果一致:要么都不能看到下载链接要么都能看到下载链接。

其实discuz最大的问题是帖子表cdb_threads。所以一般来说对这张表做了cache就会给论坛减轻很大的压力。

笔者做了尝试,效果还可以。所以把方法给大家看看。

先装memcache:http://blog.csdn.net/luojianlong/archive/2008/05/05/2393271.aspx.这里就不做赘述了。

1.在config.inc.php中增加

$memcachehost = '127.0.0.1';
$memcacheport = 11211;

2.在include/common.inc.php中
$mem = new Memcache;
$mem->connect($memcachehost,$memcacheport);

3.在viewthread.php中

找到

$newpostanchor = $postcount = $ratelogpids = 0;

$onlineauthors = array();

在下面加上

// added by rubeljl for memcache the first page of viewthread 2009.6.8 start
$postlist       = Array();
$bUpdateMem     = false;
if( 1 == $page ){
        $postlist       = $mem->get( 'viewthread_' . $tid . '_1');
        $bUpdateMem     = empty( $postlist ) ? false : true;
}

$bHasAttachment = false;
if( !is_array( $postlist ) || empty( $postlist ) ){
// added by rubeljl for memcache the first page of viewthread 2009.6.8 end

找到:while($post = $db->fetch_array($query)) {

在下面增加:

if( $post['attachment'] ){
        $bHasAttachment = true;
}

找到$postlist[$post['pid']] = viewthread_procpost($post);

在下面增加:

if( 1 == $page && false === $bHasAttachment ){
                $mem->set( 'viewthread_' . $tid . '_1',$postlist,1000 );
        }
}

4.在topicadmin.php中

找到$db->query(DELETE FROM {$tablepre}posts WHERE pid IN ($pids));

下面添加:

$mem->delete( 'viewthread_' . $tid . '_1' );

找到:$db->query(DELETE FROM {$tablepre}myposts WHERE tid='$othertid');

下面添加:

$mem->delete( 'viewthread_' . $tid . '_1' );

5.在include/newreply.inc.php中

找到$pid = $db->insert_id();

下面添加:$mem->delete( 'viewthread_' . $tid . '_1' );

相关文章

**本资源可免费获取,请至尾部读阅!**Discuz素材资源交易论...
分享一下我老师大神的人工智能教程吧。零基础!通俗易懂!风...
最近工作需要IIS,自己的电脑又是Windows7系统,找了下安装的...
首先就是discuz,用起来真的是特别的好用,搭建的网站真的非...
1.找到图片路径拼装文件首先打开根目录下的template目录找到...
打开NavicatforMySQL找到数据表 pre_ucenter_members 把密...