调试自动清理脚本可以帮助你确保脚本按预期工作。以下是调试步骤:

  1. 添加日志记录

    • 在清理脚本中添加日志记录,以便跟踪脚本的执行情况。可以在 /apps/home/controller/ExtLabelController.php 中添加日志记录:
      php
       
      // 自动会话清理脚本
      public function clean_session()
      {
      check_dir(RUN_PATH . '/archive', true);
      $ticketFile = RUN_PATH . '/archive/session_ticket.php';
      if (!file_exists($ticketFile)) {
      $data = (object)['expire_time' => time() - 60 * 60 * 24]; // 初始化清理时间
      create_file($ticketFile, "<?php exit();?>".json_encode($data), true);
      } else {
      $data = json_decode(trim(substr(file_get_contents($ticketFile), 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($ticketFile, "<?php exit();?>".json_encode($data), true);
      // 添加日志记录
      error_log("Session cleaned at " . date('Y-m-d H:i:s') . "\n", 3, RUN_PATH . '/archive/clean_session.log');
      } else {
      // 添加日志记录
      error_log("Failed to clean session at " . date('Y-m-d H:i:s') . "\n", 3, RUN_PATH . '/archive/clean_session.log');
      }
      }
      }

  2. 查看日志文件

    • 日志文件将保存在 RUN_PATH/archive/clean_session.log 中。
    • 打开该日志文件,查看清理脚本的执行情况。
  3. 效果说明

    • 通过日志记录,你可以跟踪清理脚本的执行情况,确保脚本按预期工作。