当前位置:首页>python>Part 3:Python 迭代器与生成器

Part 3:Python 迭代器与生成器

  • 2026-08-22 01:08:03
Part 3:Python 迭代器与生成器

迭代器与生成器

我们在使用 Python 编程的时候经常会用到一个 for 循环 for i in range(10): ,你知道它背后的逻辑是什么样的吗?

Python 的 for 循环不是直接遍历对象,底层是迭代器协议的自动化实现。

可迭代对象 Iterable VS 迭代器 Iterator:

  • 可迭代对象 Iterable :只要对象实现了 __iter__() 方法,就是可迭代对象。

    • 常见的可迭代对象有 listtuplestrdictset、生成器等。
  • 迭代器 Iterator:同时实现了 __iter__() 和 __next__() 方法的对象:

    • __iter__() 方法返回对象自身。
    • __next__() 方法返回下一个元素;遍历完毕抛出 StopIteration 异常。

Python 中只要是可迭代对象 Iterable 就可以被 for 循环遍历。

from collections.abc import Iterableisinstance(obj, Iterable)  # 结果为 True 就可以被 for 循环遍历for x in obj:    循环体

在 for i in range(10): 循环遍历语句中,range(10) 本质就是创建一个可迭代对象 Iterable,但它并不是迭代器 Iterator,for 循环底层的执行逻辑如下:

# for x in obj:#     循环体# for 循环底层实现,伪代码:iterator = iter(obj) # iter() 将可迭代对象转换成迭代器whileTrue:try:        item = next(iterator)        循环体except StopIteration:break

所以只要是可迭代对象就可以被 for 循环遍历,但反过来,能被 for 循环遍历的不一定是可迭代对象。

从 Python 的设计思想层面来看,for 循环的核心机制是迭代器协议 Iterable 。但 Python 为了兼容历史旧版本,保留了不是可迭代对象但实现了 __getitem__() 方法并且支持整数从 0 开始索引的对象仍可被 for 循环遍历,Python 会为其自动创建一个迭代器。

classDemo:def__getitem__(self, index):if index >= 10:raise IndexErrorreturn indexdemo = Demo()from collections.abc import Iterableisinstance(demo, Iterable)  # Falsefor i in demo:  # 仍可遍历    print(i)

自定义迭代器

实现一个斐波那契数列迭代器:

classFibonacciIterator:"""一个可以无限生成斐波那契数列的迭代器"""def__init__(self, max_count=None):        self.max_count = max_count        self.count = 0        self.a, self.b = 01def__iter__(self):return selfdef__next__(self):if self.max_count isnotNoneand self.count >= self.max_count:raise StopIteration        value = self.a        self.a, self.b = self.b, self.a + self.b        self.count += 1return value
# 使用fib = FibonacciIterator(10)for num in fib:    print(num, end=" ")  # 0 1 1 2 3 5 8 13 21 34
# 等价写法whileTrue:try:        item = next(fib) # 或者 item = fib.__next__()        print(num, end=" ")except StopIteration:break

生成器 Generator —— 优雅的迭代器工厂

生成器是一种特殊的迭代器,它不需要显式定义 __iter__ 和 __next__ 方法,Python 解释器会自动生成这些方法。

生成器两种形式:

  • 生成器函数,使用 yield 关键字 —— 函数的"暂停与恢复"。当函数遇到 yield 时:

    • 暂停函数执行
    • 保存当前所有局部变量状态
    • 返回 yield 后面的值给调用者
    • 下次调用 next() 时,从暂停点继续执行
  • 生成器表达式:类似列表推导式 [x for x in range(100)],生成器表达式使用圆括号(x for x in range(100)) 。

    • 列表推导式会立刻计算所有元素,并把全部结果存放在内存列表中,占用更多内存;优势是数据常驻内存,可以重复遍历、支持索引和切片。

    • 生成器表达式并不会提前计算元素,仅仅创建一个生成器对象,采用惰性求值:只有迭代取值的时候,才按需生成下一个元素,初始内存开销很小。但生成器本质是迭代器,元素只能一次性消费,遍历完成后无法再次从头使用,同时不支持索引、切片操作

    • 当元素数量巨大时,列表推导式内存开销更大;如果元素很少,差距可以忽略。

    • 数据量小、需要多次遍历,列表推导式合适;海量数据、不需要重复读取、想节省内存,生成器表达式合适。

      import syslist_comp = [i for i in range(1000000)]gen_exp = (i for i in range(1000000))print(sys.getsizeof(list_comp))  # 约 8MBprint(sys.getsizeof(gen_exp))    # 约 120 字节(固定!)
defsimple_generator():    print("=== 开始执行 ===")yield1    print("恢复执行,获取第二个值")yield2    print("恢复执行,获取第三个值")yield3    print("=== 函数结束,即将抛出 StopIteration ===")print(type(simple_generator))   # <class 'function'>  生成器函数本质只是一个函数from collections.abc import Iteratorgen = simple_generator()    # 当生成器函数被调用的时候,函数体不会立即执行,而是返回一个迭代器对象print(type(gen))# <class 'generator'>  迭代器print(isinstance(gen, Iterator))# Trueg = (x for x in range(100))  # 生成器表达式,本质就是一个迭代器print(isinstance(g, Iterator))# True
defsimple_generator():    print("=== 开始执行 ===")yield1    print("恢复执行,获取第二个值")yield2    print("恢复执行,获取第三个值")yield3    print("=== 函数结束,即将抛出 StopIteration ===")gen = simple_generator()print(next(gen))print(next(gen))print(next(gen))print(next(gen))

运行:

=== 开始执行 ===1恢复执行,获取第二个值2恢复执行,获取第三个值3=== 函数结束,即将抛出 StopIteration ===StopIteration

如果使用迭代器实现上面生成器函数的效果,那么将是这样的:

classGeneratorSimulator:def__init__(self):        self.ip = 0        self.finished = Falsedef__iter__(self):return selfdef__next__(self):if self.finished:raise StopIterationif self.ip == 0:            print("=== 开始执行 ===")            self.ip = 1return1elif self.ip == 1:            print("恢复执行,获取第二个值")            self.ip = 2return2elif self.ip == 2:            print("恢复执行,获取第三个值")            self.ip = 3return3elif self.ip == 3:            print("=== 函数结束,即将抛出 StopIteration ===")            self.finished = Trueraise StopIterationgen = GeneratorSimulator()print(next(gen))print(next(gen))print(next(gen))print(next(gen))

运行:

=== 开始执行 ===1恢复执行,获取第二个值2恢复执行,获取第三个值3=== 函数结束,即将抛出 StopIteration ===StopIteration

虽然两者的最终效果是一样的,但其背后的底层原理完全不同。

从 CPython 视角来看,真正的生成器函数的底层原理是靠一个结构体记录函数的运行状态:

typedefstruct {    PyObject_HEAD    PyFrameObject *gi_frame; // 帧对象:保存局部变量和字节码的位置    PyObject *gi_code;   // 代码对象char gi_running;   // 是否正在运行char gi_suspended;   // 是否暂停在 yield} genobject;

每次调用 next(gen)

  1. 恢复 gi_frame 中保存的字节码位置
  2. 执行字节码直到遇到 YIELD_VALUE 指令
  3. 暂停执行,保存当前帧状态
  4. 返回 yield 的值

生成器实现斐波那契数列

deffibonacci_generator(max_count=None):"""生成器版本的斐波那契,代码更简洁"""    a, b = 01    count = 0while max_count isNoneor count < max_count:yield a        a, b = b, a + b        count += 1for num in fibonacci_generator(10):    print(num, end=" ")  # 输出 0 1 1 2 3 5 8 13 21 34

和前面那段使用迭代器实现的斐波那契数列相比代代码量要少很多。

生成器高级特性

send() 方法双向通信

defecho_generator():    received = yield"准备接收"whileTrue:        received = yieldf"收到:{received}"gen = echo_generator()print(next(gen))   # 准备接收print(gen.send("hello")) # 收到:helloprint(gen.send("world")) # 收到:world
  • 首次启动生成器必须使用 next(gen) 或 gen.send(None),因为生成器初始时停在函数开头,需要一个 yield 来接收第一个值。
  • send(value) 会恢复执行,并将 value 赋值给当前 yield 表达式的结果。

throw() / close() 异常处理与资源释放

defsafe_generator():try:yield"运行中"except ValueError:yield"捕获到 ValueError"finally:        print("资源清理(关闭文件、数据库连接等)")gen = safe_generator()print(next(gen))             # 运行中print(gen.throw(ValueError))   # 捕获到 ValueErrorgen.close()                  # 输出: 资源清理...

生成器函数异常抛出方式:

  • try 代码段运行发生异常。
  • 外部 throw() 方法主动抛出异常。

yield from 生成器的委托(子生成器)

yield from 用于将迭代任务委托给另一个生成器:

defsub_generator():yield1yield2yield3defmain_generator():yield"开始"yieldfrom sub_generator()  # 完全委托yield"结束"for item in main_generator():    print(item)  # 开始 1 2 3 结束

yield from 处理嵌套列表扁平化处理:

defflatten(nested_list):for sublist in nested_list:if isinstance(sublist, list):yieldfrom flatten(sublist)  # 递归委托else:yield sublistnested = [1, [2, [34], 5], 6]print(list(flatten(nested)))  # [1, 2, 3, 4, 5, 6]

生成器妙用 —— 依赖注入

FastAPI 数据库会话依赖注入

from fastapi import FastAPI, Dependsfrom sqlalchemy import create_enginefrom sqlalchemy.orm import sessionmaker, Sessionapp = FastAPI()engine = create_engine("Database_url")SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)defget_db() -> Session: db = SessionLocal()try:yield db  # 将数据库会话注入到路由  db.commit()  # 如果一切正常,提交事务except Exception:  db.rollback() # 出错回滚raisefinally:  db.close()  # 数据库事务后关闭连接,释放资源# 路由:依赖注入@app.get("/items/{item_id}")defread_item(item_id: int, db: Session = Depends(get_db)):"""    db 参数从 get_db 注入    当路由函数执行完毕后,get_db 的 finally 会自动执行    """    item = db.query(Item).filter(Item.id == item_id).first()return item

执行流程:

1. 请求进入 → FastAPI 调用 get_db()2. get_db() 执行到 yield db → 暂停,db 被注入到路由3. 路由函数执行(使用 db)4. 路由返回响应 → FastAPI 继续执行 get_db()5. 执行 commit/rollback → finally 中的 close()6. 响应返回给客户端

Redis 依赖注入

# 创建 Redis 连接池redis_pool = redis.ConnectionPool.from_url("Redis_Url",    decode_responses=True,    socket_connect_timeout=5,    socket_timeout=5,    retry_on_timeout=True,    health_check_interval=30,    max_connections=20)defget_redis():"""依赖注入:从连接池获取 Redis 连接"""    client = redis.Redis(connection_pool=redis_pool)try:yield clientexcept redis.ConnectionError as e:        logger.error(f"Redis connection error: {e}")raisefinally:        client.close()

yield 在这里实现了"资源的获取与释放"的完美配对,这是依赖注入中生命周期管理的最佳实践。




最新文章

随机文章

基本 文件 流程 错误 SQL 调试
  1. 请求信息 : 2026-08-22 03:28:16 HTTP/2.0 GET : https://f.mffb.com.cn/a/507481.html
  2. 运行时间 : 0.205363s [ 吞吐率:4.87req/s ] 内存消耗:4,511.88kb 文件加载:140
  3. 缓存信息 : 0 reads,0 writes
  4. 会话信息 : SESSION_ID=b37ff8866bd9c83e2489f3fc80c655e1
  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.001077s ] mysql:host=127.0.0.1;port=3306;dbname=f_mffb;charset=utf8mb4
  2. SHOW FULL COLUMNS FROM `fenlei` [ RunTime:0.001374s ]
  3. SELECT * FROM `fenlei` WHERE `fid` = 0 [ RunTime:0.011804s ]
  4. SELECT * FROM `fenlei` WHERE `fid` = 63 [ RunTime:0.006412s ]
  5. SHOW FULL COLUMNS FROM `set` [ RunTime:0.001284s ]
  6. SELECT * FROM `set` [ RunTime:0.000516s ]
  7. SHOW FULL COLUMNS FROM `article` [ RunTime:0.001389s ]
  8. SELECT * FROM `article` WHERE `id` = 507481 LIMIT 1 [ RunTime:0.000988s ]
  9. UPDATE `article` SET `lasttime` = 1787340496 WHERE `id` = 507481 [ RunTime:0.002750s ]
  10. SELECT * FROM `fenlei` WHERE `id` = 66 LIMIT 1 [ RunTime:0.000576s ]
  11. SELECT * FROM `article` WHERE `id` < 507481 ORDER BY `id` DESC LIMIT 1 [ RunTime:0.000970s ]
  12. SELECT * FROM `article` WHERE `id` > 507481 ORDER BY `id` ASC LIMIT 1 [ RunTime:0.001114s ]
  13. SELECT * FROM `article` WHERE `id` < 507481 ORDER BY `id` DESC LIMIT 10 [ RunTime:0.001811s ]
  14. SELECT * FROM `article` WHERE `id` < 507481 ORDER BY `id` DESC LIMIT 10,10 [ RunTime:0.001754s ]
  15. SELECT * FROM `article` WHERE `id` < 507481 ORDER BY `id` DESC LIMIT 20,10 [ RunTime:0.002327s ]
0.209095s