跳到主内容
爱奇艺广告888联盟广告森林广告广告位3
首页 > 建站运维> 教程pbootcms网站自动清理runtime缓存方法

教程pbootcms网站自动清理runtime缓存方法

建站运维170 浏览2024-10-20

教程pbootcms网站自动清理runtime缓存方法

最近有朋友在用到pbootcms建网站,他购买的是一个空间比较小的虚拟主机,时间一长空间就满了,网站就没法运行,只能手动删除下runtime这个缓存目录,如果我们要让系统自动删除清理缓存目录,要怎么操作呢?

首先将需要修改的问题做好备份,找到/apps/home/controller/ExtLabelController.php文件

找到代码

    // 测试扩展单个标签    private function test()    {        $this->content = str_replace('{pboot:userip}', get_user_ip(), $this->content);    }}

在下面加入

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>

这样在有人访问网站时候就会清理缓存!ps:在这里需要注意,如果您的空间够用的话不建议这么操作,毕竟缓存的话对网站访问速度还是有帮助的。

下载地址

立即下载
如果下载不了,请点击 下载说明安装教程
滚动至顶部