示例#1
0
                        echo ' failed ' . PHP_EOL;
                    }
                }
            }
        }
    } else {
        echo "no table to delete " . PHP_EOL;
    }
}
/**
 * 删除一个月前的日志
 */
function del_stats()
{
    $time_key = date("Y-m-d", time() - 3600 * 24 * 30);
    $tables = array('stats', 'stats_client', 'stats_server');
    foreach ($tables as $table) {
        while (true) {
            $sql1 = "DELETE FROM `" . $table . "` where date_key < '{$time_key}' limit 1000";
            echo $sql1 . "\n";
            $res = Swoole::$php->db->query($sql1);
            if ($res === false) {
                break;
            }
        }
    }
}
$cron = new Cron();
$cron->set_job('del_log');
$cron->set_job('del_stats');
$cron->run();