当前位置:首页>python>Python itertools模块全解析:掌握迭代器工具,让你的代码效率飙升!

Python itertools模块全解析:掌握迭代器工具,让你的代码效率飙升!

  • 2026-03-26 09:17:15
Python itertools模块全解析:掌握迭代器工具,让你的代码效率飙升!
引言:为什么你的循环代码又慢又占内存?
在日常Python开发中,你是否经常遇到以下痛点:
  • 处理百万级数据时内存爆炸:加载整个CSV文件到内存,结果程序因OOM崩溃
  • 多层嵌套循环代码冗长:三层for循环加上if判断,代码可读性差,维护困难
  • 生成组合排列效率低下:手动实现排列组合算法,性能差且容易出错
  • 需要无限序列却不知如何生成:模拟数据流、编号生成时只能硬编码有限数据
如果你有这些困扰,那么itertools模块就是你的终极解决方案!作为Python标准库的核心组件,itertools提供了一系列经过C语言优化的迭代器工具,能够将复杂的循环逻辑简化为一两行代码,同时在内存效率和执行速度上都有显著提升。
今天,我们将深入剖析itertools模块的核心功能,通过丰富的实战案例和代码示例,让你彻底掌握这个"Python高效编程的秘密武器"!
一、itertools模块概述
1.1 模块定位与设计哲学
itertools模块是Python标准库中专门用于创建和操作迭代器的工具集。它的设计灵感来自于APL、Haskell和SML等函数式编程语言,将这些语言中的迭代器构造工具"重新铸造"成适合Python的形式。
核心设计理念体现在三个方面:
  1. 惰性求值(Lazy Evaluation):只在需要时生成下一个值,不预先计算所有结果
  2. 内存高效:处理大数据集时保持恒定的内存占用,避免中间列表创建
  3. 组合性:工具之间可以自由组合,构建复杂的数据处理管道
1.2 模块结构全景图
itertools模块包含三大类共20多个函数,以下是主要函数的分类概览:
类别
核心函数
主要用途
关键特性
无限迭代器
count()
生成无限等差数列
起始值+步长,内存恒定
cycle()
无限循环给定序列
缓存输入序列,循环输出
repeat()
重复指定对象
可指定重复次数或无限重复
有限迭代器
chain()
连接多个迭代器
零拷贝拼接,无中间列表
compress()
条件过滤数据
使用布尔掩码筛选元素
groupby()
按键分组连续元素
要求输入已排序
islice()
迭代器切片操作
支持start/stop/step参数
takewhile()
取元素直到条件不满足
条件为假时停止
dropwhile()
跳过元素直到条件不满足
条件为假后开始取
filterfalse()
返回不满足条件的元素
filter的反向操作
组合生成器
product()
计算笛卡尔积
替代多层嵌套循环
permutations()
生成所有排列
考虑元素顺序
combinations()
生成所有组合
不考虑元素顺序
combinations_with_replacement()
允许重复的组合
元素可重复出现
接下来,我们将重点解析其中最常用、最强大的10个函数,并通过实战案例展示其应用价值。
二、无限迭代器:处理无穷序列的利器
2.1 count:永不停止的计数器
count()函数生成一个无限递增(或递减)的等差数列,是生成编号、时间戳、测试数据的理想工具。
基础用法:
import itertools# 从10开始,步长为2的无限序列counter = itertools.count(start=10, step=2)print("前5个值:", [next(counter) for _ in range(5)])# 输出: [10, 12, 14, 16, 18]# 支持浮点数和负数float_counter = itertools.count(2.50.5)print("浮点序列:", [next(float_counter) for _ in range(3)])# 输出: [2.5, 3.0, 3.5]
实战应用:生成唯一ID
defgenerate_ids(prefix="ID"):"""生成带前缀的唯一ID序列"""    counter = itertools.count(1)whileTrue:yieldf"{prefix}_{next(counter):06d}"# 使用示例id_generator = generate_ids("USER")user_ids = [next(id_generator) for _ in range(5)]print("用户ID:", user_ids)# 输出: ['USER_000001', 'USER_000002', 'USER_000003', 'USER_000004', 'USER_000005']
2.2 cycle:无限循环的模式生成器
cycle()函数无限重复给定的可迭代对象,适用于轮询任务、循环状态、周期模式等场景。
基础用法:
import itertools# 无限循环颜色序列colors = itertools.cycle(['红''黄''绿'])traffic_lights = [next(colors) for _ in range(7)]print("交通灯序列:", traffic_lights)# 输出: ['红''黄''绿''红''黄''绿''红']# 循环有限次数的应用limited_cycle = zip(range(10), itertools.cycle(['A''B''C']))print("有限循环:"list(limited_cycle))# 输出: [(0'A'), (1'B'), (2'C'), (3'A'), ...]
实战应用:负载均衡轮询
classLoadBalancer:"""简单的负载均衡器 - 轮询分发请求"""def__init__(self, servers):        self.servers = list(servers)        self.cycle = itertools.cycle(self.servers)defget_next_server(self):"""获取下一个服务器"""return next(self.cycle)defadd_server(self, server):"""动态添加服务器"""        self.servers.append(server)# 重新创建cycle以包含新服务器        self.cycle = itertools.cycle(self.servers)# 使用示例lb = LoadBalancer(['server1''server2''server3'])for i in range(6):    print(f"请求{i+1} → {lb.get_next_server()}")# 输出: 请求1 → server1, 请求2 → server2, 请求3 → server3, 请求4 → server1, ...
2.3 repeat:重复元素的生成器
repeat()函数重复返回指定的对象,可用于初始化数据、填充默认值、生成常量序列。
基础用法:
import itertools# 无限重复infinite_zeros = itertools.repeat(0)print("无限零:", [next(infinite_zeros) for _ in range(5)])# 输出: [00000]# 指定重复次数limited_repeat = itertools.repeat('Python'3)print("有限重复:"list(limited_repeat))# 输出: ['Python''Python''Python']
实战应用:矩阵初始化
definitialize_matrix(rows, cols, value=0):"""初始化二维矩阵"""return [list(itertools.repeat(value, cols)) for _ in range(rows)]# 使用示例matrix = initialize_matrix(340.0)print("初始化矩阵:")for row in matrix:    print(row)# 输出:# [0.0, 0.0, 0.0, 0.0]# [0.0, 0.0, 0.0, 0.0]# [0.0, 0.0, 0.0, 0.0]
三、有限迭代器:数据处理的核心工具
3.1 chain:迭代器的无缝拼接
chain()函数将多个迭代器连接成一个连续的序列,比使用extend()+操作符更内存高效。
基础用法:
import itertools# 连接多个列表list1 = [123]list2 = ['a''b''c']list3 = [TrueFalse]chained = itertools.chain(list1, list2, list3)print("连接结果:"list(chained))# 输出: [1, 2, 3, 'a', 'b', 'c', True, False]# 扁平化嵌套列表(一层)nested = [[12], [34], [56]]flattened = list(itertools.chain.from_iterable(nested))print("扁平化结果:", flattened)# 输出: [1, 2, 3, 4, 5, 6]
实战应用:合并多个数据源
defmerge_log_files(file_paths):"""合并多个日志文件的内容"""defread_lines(file_path):with open(file_path, 'r', encoding='utf-8'as f:for line in f:yield line.strip()# 创建多个生成器    file_generators = [read_lines(path) for path in file_paths]# 合并所有生成器    merged = itertools.chain.from_iterable(file_generators)return merged# 模拟使用log_files = ['app.log''error.log''access.log']# 实际使用时替换为真实文件路径# merged_logs = merge_log_files(log_files)# for line in itertools.islice(merged_logs, 5):#     print(line)
3.2 compress:基于掩码的条件筛选
compress()函数根据第二个参数提供的布尔掩码来筛选第一个参数中的元素,比列表推导式更直观。
基础用法:
import itertools# 基础筛选data = ['苹果''香蕉''橙子''葡萄''芒果']mask = [10101]  # 1保留,0过滤selected = list(itertools.compress(data, mask))print("筛选结果:", selected)# 输出: ['苹果', '橙子', '芒果']# 动态生成掩码numbers = range(10)even_mask = [n % 2 == 0for n in numbers]evens = list(itertools.compress(numbers, even_mask))print("偶数:", evens)# 输出: [0, 2, 4, 6, 8]
实战应用:考试通过名单筛选
deffilter_passed_students(students, scores, passing_score=60):"""筛选考试通过的学生"""# 生成通过掩码    passed_mask = [score >= passing_score for score in scores]# 筛选学生    passed_students = list(itertools.compress(students, passed_mask))    passed_scores = list(itertools.compress(scores, passed_mask))return list(zip(passed_students, passed_scores))# 使用示例students = ['张三''李四''王五''赵六''钱七']scores = [8552904875]passed = filter_passed_students(students, scores, 60)print("通过学生及成绩:", passed)# 输出: [('张三', 85), ('王五', 90), ('钱七', 75)]
3.3 groupby:连续数据的分组大师
groupby()函数将连续出现的相同键值元素分组,是数据分析中常用的工具。
重要提醒:使用前必须对数据进行排序!
基础用法:
import itertools# 基础分组(注意需要先排序)data = [('A'1), ('A'2), ('B'3), ('B'4), ('C'5), ('A'6)]# 错误示范:直接分组会得到错误结果# 正确做法:先按键排序sorted_data = sorted(data, key=lambda x: x[0])# 按第一个元素分组for key, group in itertools.groupby(sorted_data, key=lambda x: x[0]):    group_list = list(group)    print(f"组 {key}{group_list}, 数量: {len(group_list)}")# 输出:# 组 A: [('A', 1), ('A', 2)], 数量: 2# 组 B: [('B', 3), ('B', 4)], 数量: 2  # 组 C: [('C', 5)], 数量: 1# 注意:后面的('A', 6)在排序后不连续,所以不会与前面的A合并
实战应用:日志按日期聚合分析
from datetime import datetimeimport itertools# 模拟日志数据logs = [    {'time''2024-03-17 08:30''level''INFO''message''服务启动'},    {'time''2024-03-17 09:15''level''ERROR''message''数据库连接失败'},    {'time''2024-03-17 09:20''level''WARN''message''高内存使用'},    {'time''2024-03-18 10:00''level''INFO''message''定时任务执行'},    {'time''2024-03-18 10:05''level''ERROR''message''文件写入失败'},]# 提取日期作为分组键for log in logs:    log['date'] = log['time'].split()[0]# 按日期排序logs.sort(key=lambda x: x['date'])# 按日期分组统计for date, group in itertools.groupby(logs, key=lambda x: x['date']):    group_list = list(group)    error_count = sum(1for log in group_list if log['level'] == 'ERROR')    print(f"{date}: 共{len(group_list)}条日志, 其中{error_count}条错误")# 输出:# 2024-03-17: 共3条日志, 其中1条错误# 2024-03-18: 共2条日志, 其中1条错误
3.4 islice:迭代器的智能切片
islice()函数对迭代器进行切片操作,类似于列表切片但适用于无限序列,且不消耗额外内存。
基础用法:
import itertools# 基础切片numbers = range(100)sliced = itertools.islice(numbers, 1020)  # 取索引10-19print("切片结果:"list(sliced))# 输出: [10, 11, 12, 13, 14, 15, 16, 17, 18, 19]# 无限序列切片infinite = itertools.count(0)first_5 = list(itertools.islice(infinite, 5))print("无限序列前5个:", first_5)# 输出: [0, 1, 2, 3, 4]# 指定步长with_step = itertools.islice(range(20), 0203)print("步长为3:"list(with_step))# 输出: [0, 3, 6, 9, 12, 15, 18]
实战应用:分批读取大文件
defread_file_in_batches(file_path, batch_size=1000):"""分批读取大文件,避免内存溢出"""with open(file_path, 'r', encoding='utf-8'as f:whileTrue:# 读取一批行            batch = list(itertools.islice(f, batch_size))ifnot batch:breakyield [line.strip() for line in batch]# 模拟使用# for batch_num, batch in enumerate(read_file_in_batches('large_data.csv', 10000)):#     print(f"处理第{batch_num+1}批,共{len(batch)}行")#     # 处理本批次数据...
四、组合生成器:数学问题的编程解法
4.1 product:多层循环的终极替代者
product()函数计算多个可迭代对象的笛卡尔积,是替代多层嵌套for循环的最佳工具。
基础用法:
import itertools# 两个集合的笛卡尔积colors = ['红''绿''蓝']sizes = ['S''M''L']combinations = list(itertools.product(colors, sizes))print("颜色-尺寸组合:", combinations)# 输出: [('红''S'), ('红''M'), ('红''L'), ('绿''S'), ...]# 多个维度的组合dimensions = [    ['A''B'],    [12],    ['X''Y''Z']]multi_comb = list(itertools.product(*dimensions))print(f"三维组合数量: {len(multi_comb)}")# 输出: 12 (2×2×3)
实战应用:生成测试用例矩阵
defgenerate_test_cases():"""生成全参数组合的测试用例"""    browsers = ['Chrome''Firefox''Safari']    operating_systems = ['Windows''macOS''Linux']    screen_resolutions = ['1920x1080''1366x768''1440x900']    languages = ['en-US''zh-CN''ja-JP']# 生成所有组合    test_cases = itertools.product(        browsers, operating_systems, screen_resolutions, languages    )for i, (browser, os, resolution, lang) in enumerate(test_cases, 1):        print(f"用例{i}{browser} on {os}{resolution}{lang}")# 这里可以实际执行测试...# 使用示例(限制输出前3个)print("测试用例示例:")for case in itertools.islice(generate_test_cases(), 3):    print(case)
4.2 permutations:顺序敏感的全排列
permutations()函数生成序列的所有排列,适用于密码破解、旅行商问题等场景。
基础用法:
import itertools# 基础排列items = ['A''B''C']perms = list(itertools.permutations(items2))print("2个元素的所有排列:", perms)# 输出: [('A''B'), ('A''C'), ('B''A'), ('B''C'), ('C''A'), ('C''B')]# 全排列(默认r=序列长度)full_perms = list(itertools.permutations(items))print(f"全排列数量: {len(full_perms)}")# 输出: 6 (3!)
实战应用:生成所有可能的密码组合
defgenerate_password_combinations(chars, length):"""生成指定字符集和长度的所有密码组合"""# 注意:排列数量可能非常大,需要谨慎使用return itertools.permutations(chars, length)# 安全使用示例(限制输出)chars = ['a''b''c''1''2']length = 3print(f"从{len(chars)}个字符中选取{length}个的所有排列:")for i, pwd in enumerate(itertools.islice(generate_password_combinations(chars, length), 10)):    print(f"  {i+1}{''.join(pwd)}")
4.3 combinations:顺序不敏感的组合
combinations()函数生成序列的所有组合,不考虑元素顺序,适用于特征选择、子集枚举等场景。
基础用法:
import itertools# 基础组合items = ['A''B''C''D']combs = list(itertools.combinations(items2))print("2个元素的所有组合:", combs)# 输出: [('A''B'), ('A''C'), ('A''D'), ('B''C'), ('B''D'), ('C''D')]# 计算组合数量(不实际生成)from math import combn = 10k = 3print(f"C({n},{k}) = {comb(n, k)}")# 输出: C(10,3) = 120
实战应用:特征选择的所有可能组合
from itertools import combinationsimport numpy as npdefevaluate_feature_combinations(features, target, model, k=3):"""评估所有k个特征的组合"""    n_features = len(features)    feature_names = list(features.columns)    best_score = -np.inf    best_combo = None# 遍历所有k个特征的组合for combo in combinations(range(n_features), k):# 选择特征子集        X_subset = features.iloc[:, list(combo)]# 训练模型并评估(这里简化为随机分数)# 实际应用中需要使用交叉验证        score = np.random.random()  # 模拟评估分数if score > best_score:            best_score = score            best_combo = [feature_names[i] for i in combo]return best_combo, best_score# 模拟使用# import pandas as pd# features = pd.DataFrame(np.random.randn(100, 10))# target = pd.Series(np.random.randn(100))# best_features, score = evaluate_feature_combinations(features, target, None, k=3)
五、高级技巧与性能优化
5.1 构建数据处理管道
itertools的真正威力在于组合使用各个函数,构建高效的数据处理管道。
示例:日志处理流水线
import itertoolsimport refrom collections import Counterdefprocess_logs(log_lines):"""日志处理流水线"""# 1. 过滤空行    non_empty = filter(lambda x: x.strip(), log_lines)# 2. 提取时间戳和消息    parsed = map(lambda line: parse_log_line(line), non_empty)# 3. 过滤错误日志    errors = filter(lambda x: x['level'] == 'ERROR', parsed)# 4. 按小时分组    errors_by_hour = {}for hour, group in itertools.groupby(errors, key=lambda x: x['time'].hour):        errors_by_hour[hour] = list(group)return errors_by_hourdefparse_log_line(line):"""解析单行日志(简化版)"""# 实际应用中这里会有更复杂的正则匹配return {'time': datetime.strptime(line[:19], '%Y-%m-%d %H:%M:%S'),'level': line[20:25].strip(),'message': line[26:]    }
5.2 避免常见性能陷阱
  1. 不要对大集合直接调用list()
# 危险:可能内存溢出# all_perms = list(itertools.permutations(range(15)))# 安全:使用islice限制或逐个处理for perm in itertools.islice(itertools.permutations(range(10)), 1000):    process(perm)
  1. 正确使用tee避免内存泄漏
import itertools# tee会缓存未消费的数据data = range(1000000)a, b = itertools.tee(data, 2)# 如果两个迭代器消费速度差异大,可能内存激增# 解决方案:需要多次遍历时直接转换为listcached = list(data)
  1. groupby前必须排序
# 错误:未排序直接使用groupbydata = [('A'1), ('B'2), ('A'3)]# 结果会得到3个单元素组# 正确:先排序sorted_data = sorted(data, key=lambda x: x[0])for key, group in itertools.groupby(sorted_data, key=lambda x: x[0]):    print(key, list(group))
5.3 与operator模块的协同使用
operator模块提供了函数式编程的运算符,与itertools结合可以写出更简洁的代码。
import itertoolsimport operator# 累积乘积numbers = [12345]cumulative_product = list(itertools.accumulate(numbers, operator.mul))print("累积乘积:", cumulative_product)# 输出: [1, 2, 6, 24, 120]# 按第二个元素排序data = [('apple'5), ('banana'2), ('cherry'8)]sorted_by_second = sorted(data, key=operator.itemgetter(1))print("按数量排序:", sorted_by_second)# 输出: [('banana', 2), ('apple', 5), ('cherry', 8)]
六、实战应用场景深度解析
6.1 场景一:大数据批处理与内存优化
问题: 处理10GB的日志文件,统计每个IP地址的访问次数。
传统方案: 一次性加载所有数据到内存,使用字典统计 → 内存溢出
itertools方案: 使用惰性处理,分批读取
import itertoolsfrom collections import Counterdefcount_ips_large_file(file_path, batch_size=10000):"""统计大文件中IP出现次数"""    ip_counter = Counter()with open(file_path, 'r'as f:whileTrue:# 读取一批行            batch = list(itertools.islice(f, batch_size))ifnot batch:break# 提取IP地址(假设IP在每行开头)            ips = [line.split()[0for line in batch if line.strip()]            ip_counter.update(ips)return ip_counter# 使用示例(模拟)# top_ips = count_ips_large_file('access.log').most_common(10)
6.2 场景二:算法竞赛中的组合优化
问题: 旅行商问题(TSP)的暴力解法,需要生成所有城市排列。
传统方案: 手动实现排列算法,代码复杂且效率低
itertools方案: 直接使用permutations
import itertoolsimport mathdeftsp_brute_force(distances):"""TSP暴力解法"""    n = len(distances)    cities = list(range(n))    best_path = None    min_distance = math.inf# 遍历所有排列for path in itertools.permutations(cities):# 计算路径长度        distance = 0for i in range(n):            from_city = path[i]            to_city = path[(i + 1) % n]            distance += distances[from_city][to_city]if distance < min_distance:            min_distance = distance            best_path = pathreturn best_path, min_distance# 使用示例(5个城市)# distances = [[0, 2, 9, 10], [1, 0, 6, 4], [15, 7, 0, 8], [6, 3, 12, 0]]# path, dist = tsp_brute_force(distances)
6.3 场景三:数据清洗与预处理管道
问题: 清洗包含缺失值、异常值、重复记录的数据集。
itertools方案: 构建清洗流水线
import itertoolsimport numpy as npdefdata_cleaning_pipeline(data_iter):"""数据清洗流水线"""# 1. 过滤空行    non_empty = filter(lambda x: x isnotNone, data_iter)# 2. 去除前后空格    trimmed = map(str.strip, non_empty)# 3. 解析为数值    parsed = map(parse_number, trimmed)# 4. 过滤异常值(假设范围0-100)    valid_range = filter(lambda x: 0 <= x <= 100, parsed)# 5. 分批处理(每批1000条)    batches = batched(valid_range, 1000)return batchesdefparse_number(s):"""安全解析数值"""try:return float(s)except (ValueError, TypeError):returnNonedefbatched(iterable, n):"""分批处理生成器(Python 3.12+有itertools.batched)"""    it = iter(iterable)while batch := list(itertools.islice(it, n)):yield batch
七、常见问题与解决方案
7.1 Q:itertools函数返回的迭代器可以重复使用吗?
A: 大多数迭代器只能使用一次,消费后需要重新创建。如果需要多次使用,可以使用tee()函数或转换为list
import itertoolsdata = [123]iter1, iter2 = itertools.tee(data, 2)print("迭代器1:"list(iter1))  # [1, 2, 3]print("迭代器2:"list(iter2))  # [1, 2, 3]
7.2 Q:如何处理无限迭代器的停止条件?
A: 结合islice()takewhile()或手动设置终止条件。
import itertools# 方法1:使用islice限制数量limited = itertools.islice(itertools.count(), 10)# 方法2:使用takewhile条件停止conditioned = itertools.takewhile(lambda x: x < 10, itertools.count())# 方法3:手动终止counter = itertools.count()for i in range(10):    print(next(counter))
7.3 Q:itertools和列表推导式哪个更好?
A: 根据场景选择:
  • itertools:处理大数据、无限序列、需要惰性求值时
  • 列表推导式:数据量小、需要立即使用所有结果时
# 小数据集:列表推导式更直观squares = [x**2for x in range(100)]# 大数据集或无限序列:itertools更高效from itertools import islice, countbig_squares = (x**2for x in count())first_100 = list(islice(big_squares, 100))
八、总结与延伸学习
8.1 核心要点回顾
通过今天的深度解析,我们掌握了itertools模块的三大类核心工具:
  1. 无限迭代器countcyclerepeat,处理无限序列的神器
  2. 有限迭代器chaincompressgroupbyislice,数据处理的核心工具
  3. 组合生成器productpermutationscombinations,数学问题的编程解法
8.2 实战项目建议
想要真正掌握itertools?尝试完成以下实战项目:
  1. 日志分析系统:使用groupbyCounter分析服务器日志,找出异常模式
  2. 组合优化算法:用productpermutations实现参数网格搜索
  3. 数据流处理管道:结合chainfilterfalseislice构建实时数据处理系统
  4. 测试用例生成器:利用product自动生成全参数组合的测试用例
8.3 延伸学习路径
itertools是Python标准库的冰山一角,要继续深入:
  1. 进阶方向
    • functools:高阶函数工具,与itertools配合实现函数式编程
    • collections:扩展的数据结构,与itertools结合处理复杂数据
    • more-itertools:第三方扩展库,提供更多实用工具
  2. 实战书籍推荐
    • 《Python Cookbook》第4章:迭代器与生成器
    • 《流畅的Python》第14章:迭代器、生成器和经典协程
    • 《Effective Python》第56条:用itertools处理迭代器
  3. 开源项目学习
    • 查看Python标准库源码:Lib/itertools.py
    • 学习Django ORM如何使用itertools优化查询
    • 研究Pandas内部如何利用迭代器处理大数据
8.4 最后的话
itertools模块是Python高效编程的"秘密武器",它将复杂的循环逻辑简化为几行优雅的代码,同时在内存效率和执行速度上都有显著提升。
记住:优秀的Python程序员不是记住所有API,而是知道在什么时候使用什么工具。itertools就是你工具箱中的重要组成部分,熟练掌握它,你将成为更高效的Python开发者!

下一篇预告:明天我们将探索datetime模块,学习如何优雅地处理日期和时间,避免常见的时区陷阱。敬请期待!

本文为"Python与AI智能研习社"公众号原创文章,转载请注明出处。关注公众号,获取更多Python技术干货!

最新文章

随机文章

基本 文件 流程 错误 SQL 调试
  1. 请求信息 : 2026-03-27 15:05:36 HTTP/2.0 GET : https://f.mffb.com.cn/a/482452.html
  2. 运行时间 : 0.102612s [ 吞吐率:9.75req/s ] 内存消耗:4,563.91kb 文件加载:140
  3. 缓存信息 : 0 reads,0 writes
  4. 会话信息 : SESSION_ID=f0b3c41739a0b8469eeb5eb85dabf8dd
  1. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/public/index.php ( 0.79 KB )
  2. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/autoload.php ( 0.17 KB )
  3. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/composer/autoload_real.php ( 2.49 KB )
  4. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/composer/platform_check.php ( 0.90 KB )
  5. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/composer/ClassLoader.php ( 14.03 KB )
  6. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/composer/autoload_static.php ( 4.90 KB )
  7. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-helper/src/helper.php ( 8.34 KB )
  8. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-validate/src/helper.php ( 2.19 KB )
  9. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/helper.php ( 1.47 KB )
  10. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/stubs/load_stubs.php ( 0.16 KB )
  11. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Exception.php ( 1.69 KB )
  12. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-container/src/Facade.php ( 2.71 KB )
  13. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/symfony/deprecation-contracts/function.php ( 0.99 KB )
  14. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/symfony/polyfill-mbstring/bootstrap.php ( 8.26 KB )
  15. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/symfony/polyfill-mbstring/bootstrap80.php ( 9.78 KB )
  16. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/symfony/var-dumper/Resources/functions/dump.php ( 1.49 KB )
  17. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-dumper/src/helper.php ( 0.18 KB )
  18. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/symfony/var-dumper/VarDumper.php ( 4.30 KB )
  19. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/App.php ( 15.30 KB )
  20. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-container/src/Container.php ( 15.76 KB )
  21. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/psr/container/src/ContainerInterface.php ( 1.02 KB )
  22. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/provider.php ( 0.19 KB )
  23. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Http.php ( 6.04 KB )
  24. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-helper/src/helper/Str.php ( 7.29 KB )
  25. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Env.php ( 4.68 KB )
  26. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/common.php ( 0.03 KB )
  27. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/helper.php ( 18.78 KB )
  28. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Config.php ( 5.54 KB )
  29. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/app.php ( 0.95 KB )
  30. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/cache.php ( 0.78 KB )
  31. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/console.php ( 0.23 KB )
  32. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/cookie.php ( 0.56 KB )
  33. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/database.php ( 2.48 KB )
  34. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/facade/Env.php ( 1.67 KB )
  35. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/filesystem.php ( 0.61 KB )
  36. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/lang.php ( 0.91 KB )
  37. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/log.php ( 1.35 KB )
  38. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/middleware.php ( 0.19 KB )
  39. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/route.php ( 1.89 KB )
  40. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/session.php ( 0.57 KB )
  41. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/trace.php ( 0.34 KB )
  42. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/view.php ( 0.82 KB )
  43. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/event.php ( 0.25 KB )
  44. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Event.php ( 7.67 KB )
  45. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/service.php ( 0.13 KB )
  46. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/AppService.php ( 0.26 KB )
  47. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Service.php ( 1.64 KB )
  48. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Lang.php ( 7.35 KB )
  49. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/lang/zh-cn.php ( 13.70 KB )
  50. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/initializer/Error.php ( 3.31 KB )
  51. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/initializer/RegisterService.php ( 1.33 KB )
  52. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/services.php ( 0.14 KB )
  53. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/service/PaginatorService.php ( 1.52 KB )
  54. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/service/ValidateService.php ( 0.99 KB )
  55. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/service/ModelService.php ( 2.04 KB )
  56. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-trace/src/Service.php ( 0.77 KB )
  57. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Middleware.php ( 6.72 KB )
  58. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/initializer/BootService.php ( 0.77 KB )
  59. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/Paginator.php ( 11.86 KB )
  60. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-validate/src/Validate.php ( 63.20 KB )
  61. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/Model.php ( 23.55 KB )
  62. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/concern/Attribute.php ( 21.05 KB )
  63. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/concern/AutoWriteData.php ( 4.21 KB )
  64. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/concern/Conversion.php ( 6.44 KB )
  65. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/concern/DbConnect.php ( 5.16 KB )
  66. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/concern/ModelEvent.php ( 2.33 KB )
  67. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/concern/RelationShip.php ( 28.29 KB )
  68. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-helper/src/contract/Arrayable.php ( 0.09 KB )
  69. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-helper/src/contract/Jsonable.php ( 0.13 KB )
  70. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/contract/Modelable.php ( 0.09 KB )
  71. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Db.php ( 2.88 KB )
  72. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/DbManager.php ( 8.52 KB )
  73. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Log.php ( 6.28 KB )
  74. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Manager.php ( 3.92 KB )
  75. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/psr/log/src/LoggerTrait.php ( 2.69 KB )
  76. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/psr/log/src/LoggerInterface.php ( 2.71 KB )
  77. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Cache.php ( 4.92 KB )
  78. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/psr/simple-cache/src/CacheInterface.php ( 4.71 KB )
  79. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-helper/src/helper/Arr.php ( 16.63 KB )
  80. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/cache/driver/File.php ( 7.84 KB )
  81. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/cache/Driver.php ( 9.03 KB )
  82. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/contract/CacheHandlerInterface.php ( 1.99 KB )
  83. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/Request.php ( 0.09 KB )
  84. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Request.php ( 55.78 KB )
  85. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/middleware.php ( 0.25 KB )
  86. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Pipeline.php ( 2.61 KB )
  87. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-trace/src/TraceDebug.php ( 3.40 KB )
  88. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/middleware/SessionInit.php ( 1.94 KB )
  89. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Session.php ( 1.80 KB )
  90. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/session/driver/File.php ( 6.27 KB )
  91. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/contract/SessionHandlerInterface.php ( 0.87 KB )
  92. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/session/Store.php ( 7.12 KB )
  93. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Route.php ( 23.73 KB )
  94. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/RuleName.php ( 5.75 KB )
  95. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/Domain.php ( 2.53 KB )
  96. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/RuleGroup.php ( 22.43 KB )
  97. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/Rule.php ( 26.95 KB )
  98. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/RuleItem.php ( 9.78 KB )
  99. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/route/app.php ( 1.72 KB )
  100. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/facade/Route.php ( 4.70 KB )
  101. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/dispatch/Controller.php ( 4.74 KB )
  102. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/Dispatch.php ( 10.44 KB )
  103. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/controller/Index.php ( 4.81 KB )
  104. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/BaseController.php ( 2.05 KB )
  105. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/facade/Db.php ( 0.93 KB )
  106. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/connector/Mysql.php ( 5.44 KB )
  107. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/PDOConnection.php ( 52.47 KB )
  108. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/Connection.php ( 8.39 KB )
  109. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/ConnectionInterface.php ( 4.57 KB )
  110. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/builder/Mysql.php ( 16.58 KB )
  111. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/Builder.php ( 24.06 KB )
  112. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/BaseBuilder.php ( 27.50 KB )
  113. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/Query.php ( 15.71 KB )
  114. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/BaseQuery.php ( 45.13 KB )
  115. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/TimeFieldQuery.php ( 7.43 KB )
  116. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/AggregateQuery.php ( 3.26 KB )
  117. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/ModelRelationQuery.php ( 20.07 KB )
  118. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/ParamsBind.php ( 3.66 KB )
  119. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/ResultOperation.php ( 7.01 KB )
  120. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/WhereQuery.php ( 19.37 KB )
  121. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/JoinAndViewQuery.php ( 7.11 KB )
  122. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/TableFieldInfo.php ( 2.63 KB )
  123. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/Transaction.php ( 2.77 KB )
  124. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/log/driver/File.php ( 5.96 KB )
  125. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/contract/LogHandlerInterface.php ( 0.86 KB )
  126. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/log/Channel.php ( 3.89 KB )
  127. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/event/LogRecord.php ( 1.02 KB )
  128. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-helper/src/Collection.php ( 16.47 KB )
  129. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/facade/View.php ( 1.70 KB )
  130. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/View.php ( 4.39 KB )
  131. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Response.php ( 8.81 KB )
  132. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/response/View.php ( 3.29 KB )
  133. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Cookie.php ( 6.06 KB )
  134. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-view/src/Think.php ( 8.38 KB )
  135. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/contract/TemplateHandlerInterface.php ( 1.60 KB )
  136. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-template/src/Template.php ( 46.61 KB )
  137. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-template/src/template/driver/File.php ( 2.41 KB )
  138. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-template/src/template/contract/DriverInterface.php ( 0.86 KB )
  139. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/runtime/temp/067d451b9a0c665040f3f1bdd3293d68.php ( 11.98 KB )
  140. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-trace/src/Html.php ( 4.42 KB )
  1. CONNECT:[ UseTime:0.000393s ] mysql:host=127.0.0.1;port=3306;dbname=f_mffb;charset=utf8mb4
  2. SHOW FULL COLUMNS FROM `fenlei` [ RunTime:0.000532s ]
  3. SELECT * FROM `fenlei` WHERE `fid` = 0 [ RunTime:0.000246s ]
  4. SELECT * FROM `fenlei` WHERE `fid` = 63 [ RunTime:0.000341s ]
  5. SHOW FULL COLUMNS FROM `set` [ RunTime:0.000563s ]
  6. SELECT * FROM `set` [ RunTime:0.000225s ]
  7. SHOW FULL COLUMNS FROM `article` [ RunTime:0.000530s ]
  8. SELECT * FROM `article` WHERE `id` = 482452 LIMIT 1 [ RunTime:0.000431s ]
  9. UPDATE `article` SET `lasttime` = 1774595136 WHERE `id` = 482452 [ RunTime:0.009046s ]
  10. SELECT * FROM `fenlei` WHERE `id` = 66 LIMIT 1 [ RunTime:0.000278s ]
  11. SELECT * FROM `article` WHERE `id` < 482452 ORDER BY `id` DESC LIMIT 1 [ RunTime:0.000403s ]
  12. SELECT * FROM `article` WHERE `id` > 482452 ORDER BY `id` ASC LIMIT 1 [ RunTime:0.000678s ]
  13. SELECT * FROM `article` WHERE `id` < 482452 ORDER BY `id` DESC LIMIT 10 [ RunTime:0.006331s ]
  14. SELECT * FROM `article` WHERE `id` < 482452 ORDER BY `id` DESC LIMIT 10,10 [ RunTime:0.002033s ]
  15. SELECT * FROM `article` WHERE `id` < 482452 ORDER BY `id` DESC LIMIT 20,10 [ RunTime:0.015414s ]
0.104218s