pbootcms网站自动清理runtime缓存方法.png

最近有网友买了便宜的虚机建pbootcms网站,时间一长内存就满了,网站就没法运行,找家兴网络要个解决方法,那就只能修改pbootcms代码实现pbootcms网站runtime缓存文件自动删除了,今天家兴网络教分享下如何实现runtime缓存文件夹自动删除的!

  • 找到/apps/home/controller/ExtLabelController.php文件

查找代码

    // 测试扩展单个标签

    private function test()

    {

        $this->content = str_replace('{pboot:userip}', get_user_ip(), $this->content);

    }

}

在下面加入

// www.zzzzjy.cn 自动会话清理脚本

public function clean_session()

{

    check_dir(RUN_PATH . '/archive', true);

    $data = json_decode(trim(substr(file_get_contents(RUN_PATH . '/archive/session_ticket.php'), 15)));

    if($data->expire_time && $data->expire_time < time()){

        ignore_user_abort(true);

        set_time_limit(7200);

        ob_start();

        ob_end_flush();

        flush();

        $rs = path_delete(RUN_PATH . '/session');

        if($rs){

            $data->expire_time = time() + 60 * 60 * 24; // 下一次清理时间

            create_file(RUN_PATH . '/archive/session_ticket.php', "<?php exit();?>".json_encode($data), true);

        }

    } else {

        $data->expire_time = time() - 60 * 60 * 24; // 初始化清理时间

        create_file(RUN_PATH . '/archive/session_ticket.php', "<?php exit();?>".json_encode($data), true);

    }

}

  • 保存ExtLabelController.php文件

  • 在网站模板里面加入如下代码(代码一般加入到foot.html(通用底部)或者head.html(通用头部)文件里)

代码示例:

<script src='/?p=/ExtLabel/clean_session/' async='async'></script>

感觉家兴网络分享的《pbootcms网站自动清理runtime缓存方法》有帮到你,请留下小心心在走吧!如果有哪里不懂得记得给我留言哦!