当前位置:首页>python>Python闭包详解:从基础概念到高级应用

Python闭包详解:从基础概念到高级应用

  • 2026-07-01 15:40:40
Python闭包详解:从基础概念到高级应用

引言

闭包(Closure)是Python中一个强大且重要的概念,它允许函数“记住”并访问其词法作用域中的变量,即使该函数在其定义的作用域之外执行。理解闭包对于掌握Python的函数式编程、装饰器等高级特性至关重要。本文将深入浅出地讲解闭包的核心概念、工作原理、使用场景及注意事项。

1. 闭包的基本概念

闭包可以保存函数内的变量。让我们从一个简单的例子开始:

# 外函数def outer():    a = 10    def inner():        print(f"我调用了内部函数,a的值为{a}")    # 外函数的返回值是内函数的引用    return inner

在这个函数中,内函数inner使用了外函数outer的变量a,而外函数的返回值是内函数的引用。初学者可能会觉得这段代码有些奇怪,甚至怀疑它能否正常运行。让我们看看它的执行结果:

func = outer()  # 调用outer函数,返回inner函数func()          # 调用返回的inner函数

输出结果:

我调用了内部函数,以及a的值为10

可以看到,外函数outer执行完毕后,变量a=10本应被释放,但通过闭包机制,内函数inner仍然能够访问到这个变量。这就是闭包的核心特性:内函数捕获并保存了外部函数的变量环境

2. 闭包的工作原理

2.1 变量的生命周期

正常情况下,当一个函数执行结束时,其内部的局部变量会被释放,内存被回收。但在闭包中,如果内部函数引用了外部函数的变量,Python会将这些被引用的变量"绑定"到内部函数上,延长它们的生命周期。

2.2 函数也是对象

理解闭包的关键在于理解Python的"一切皆对象"哲学。在Python中,函数、整数、字符串等都是对象。当外函数返回内函数时,实际上返回的是内函数对象的引用。

可以这样理解:

def return_object(anything):    return anything

在这个函数中,你可以传入任何对象(包括函数),并返回它。闭包中的return inner正是返回了函数对象本身,而不是函数的调用结果。

3. Python变量与对象的关系

要深入理解闭包,需要先理解Python中变量与对象的关系。

3.1 变量是对象的标签

Python中没有"变量存值"的概念,只有"变量指向对象"。所有数据都是对象,存储在内存的某个位置。变量就像是贴在对象上的标签,只存储对象的地址(引用)。

3.2 参数传递机制

Python函数传递参数时,传递的是对象引用的值(即地址)。考虑以下例子:

def change_a(a):    a = 0    return aa = 1change_a(a)print(a)  # 输出:1

为什么a的值还是1而不是0?让我们分析执行过程:

  1. 调用change_a(a)时,函数创建一个局部变量a
  2. 将外部变量a存储的地址复制给局部变量a
  3. 此时两个a变量(外部和内部)指向同一个对象1
  4. 执行a = 0时,局部变量a改为指向对象0
  5. 函数结束,局部变量a被销毁
  6. 外部变量a从未被改变,仍然指向对象1

3.3 可变对象与不可变对象

对于不可变对象(如整数、字符串、元组),修改操作实际上是创建新对象:

# 不可变对象示例def modify_immutable(x):    x = x + 1  # 创建新对象    return xnum = 10modify_immutable(num)print(num)  # 输出:10,原对象未改变

对于可变对象(如列表、字典、集合),可以原地修改:

# 可变对象示例def modify_mutable(lst):    lst[0] = 0  # 原地修改    return lstmy_list = [1, 2, 3]modify_mutable(my_list)print(my_list)  # 输出:[023],原对象被修改

4. 闭包的三个必要条件

一个完整的闭包需要满足以下三个条件:

  1. 函数嵌套
    :外部函数包含内部函数
  2. 内部函数引用外部变量
    :内部函数使用了外部函数的变量
  3. 外部函数返回内部函数
    :外部函数返回内部函数的引用(不是调用)

4.1 基础闭包示例

# 外部函数接收姓名参数def config_name(name):    # 内部函数保存外部函数的参数    def inner(msg):        print(f"{name}说:{msg}")    # 外部函数返回内部函数    return inner

使用这个闭包:

# 创建闭包实例tom = config_name("Tom")tom("你好啊")  # 输出:Tom说:你好啊jerry = config_name("Jerry")jerry("Hello!")  # 输出:Jerry说:Hello!

4.2 闭包的工作原理分析

让我们一步步分析tom = config_name("Tom")的执行过程:

  1. 调用config_name("Tom"),参数"Tom"传入函数
  2. 参数赋值给局部变量name
  3. 定义内部函数inner,它引用了外部变量name
  4. 返回inner函数对象(不是调用inner()
  5. tom
    变量现在指向这个inner函数对象,并且name参数被"锁定"为"Tom"

每次调用tom("消息")时,都会使用之前保存的name="Tom"。这就像一个"记住名字的喊话机器"。

5. 修改闭包中的外部变量

5.1 默认行为:创建新局部变量

def outer():    num = 10    def inner():        num = 20  # 这创建了一个新的局部变量,不是修改外部变量        result = num + 1        print(f"num改变之后的值为{result}")    print(f"修改前的num值为{num}")    inner()    print(f"修改后的num值为{num}")  # 仍然是10    return innerfunc = outer()func()

输出:

修改前的num值为10num改变之后的值为21修改后的num值为10num改变之后的值为21

5.2 使用nonlocal关键字

要真正修改闭包中的外部变量,需要使用nonlocal关键字:

def outer():    num = 10    def inner():        nonlocal num  # 声明num不是局部变量,而是外部变量        num = 20      # 现在修改的是外部变量        result = num + 1        print(f"num改变之后的值为{result}")    print(f"修改前的num值为{num}")    inner()    print(f"修改后的num值为{num}")  # 现在是20    return innerfunc = outer()func()

输出:

修改前的num值为10num改变之后的值为21修改后的num值为20num改变之后的值为21

6. 闭包的实际应用场景

6.1 函数工厂(创建定制化函数)

def power_factory(exponent):    """创建计算幂的函数"""    def power(base):        return base ** exponent    return power# 创建平方函数square = power_factory(2)print(square(5))  # 输出:25# 创建立方函数cube = power_factory(3)print(cube(5))    # 输出:125

6.2 状态保持

def counter():    count = 0    def increment():        nonlocal count        count += 1        return count    return increment# 创建两个独立的计数器counter1 = counter()counter2 = counter()print(counter1())  # 输出:1print(counter1())  # 输出:2print(counter2())  # 输出:1(独立的计数)print(counter1())  # 输出:3

6.3 配置函数

def logger_factory(log_level):    """创建不同日志级别的日志函数"""    def log(message):        if log_level == "DEBUG":            print(f"[DEBUG] {message}")        elif log_level == "INFO":            print(f"[INFO] {message}")        elif log_level == "ERROR":            print(f"[ERROR] {message}")    return log# 创建不同级别的日志函数debug_log = logger_factory("DEBUG")info_log = logger_factory("INFO")error_log = logger_factory("ERROR")debug_log("这是一条调试信息")info_log("程序正常运行")error_log("发生了一个错误")

7. 闭包与装饰器的关系

闭包是装饰器(Decorator)的基础。装饰器本质上是一个接受函数作为参数并返回函数的闭包。

# 简单的装饰器示例def timer_decorator(func):    """计算函数执行时间的装饰器"""    import time    def wrapper(*args, **kwargs):        start_time = time.time()        result = func(*args, **kwargs)        end_time = time.time()        print(f"{func.__name__}执行时间: {end_time - start_time:.4f}秒")        return result    return wrapper# 使用装饰器@timer_decoratordef slow_function():    import time    time.sleep(1)    return "完成"result = slow_function()  # 自动计时

8. 闭包的注意事项

8.1 内存泄漏风险

闭包会延长外部变量的生命周期,如果不当使用可能导致内存泄漏:

def create_big_closure():    big_data = [0] * 1000000  # 大对象    def inner():        return len(big_data)    return inner# big_data不会被释放,直到inner函数被销毁closure = create_big_closure()

8.2 变量捕获时机

闭包捕获的是变量的引用,而不是值。这意味着如果外部变量后续被修改,闭包中看到的是修改后的值:

def create_closures():    functions = []    for i in range(3):        def inner():            return i        functions.append(inner)    return functionsclosures = create_closures()print([f() for f in closures])  # 输出:[222],不是[012]

修正方法:使用默认参数或创建新的作用域:

def create_closures_fixed():    functions = []    for i in range(3):        def inner(x=i):  # 使用默认参数捕获当前值            return x        functions.append(inner)    return functionsclosures = create_closures_fixed()print([f() for f in closures])  # 输出:[0, 1, 2]

9. 高级闭包技巧

9.1 多层嵌套闭包

def outer(x):    def middle(y):        def inner(z):            return x + y + z        return inner    return middle# 创建闭包add_5 = outer(5)      # x=5add_5_and_10 = add_5(10)  # y=10result = add_5_and_10(15)  # z=15print(result)  # 输出:30

9.2 闭包与类方法的结合

class Calculator:    def __init__(self, initial_value=0):        self.value = initial_value    def create_adder(self):        """创建加法闭包"""        def adder(amount):            self.value += amount            return self.value        return addercalc = Calculator(10)add_to_calc = calc.create_adder()print(add_to_calc(5))   # 输出:15print(add_to_calc(10))  # 输出:25print(calc.value)       # 输出:25

10. 总结

闭包是Python中一个强大而灵活的特性,它允许函数:

  1. 记住并访问其词法作用域中的变量
  2. 创建具有"记忆"功能的函数
  3. 实现函数工厂和配置模式
  4. 为装饰器等高级特性奠定基础

掌握闭包需要理解:

  • Python的变量与对象模型
  • 作用域和命名空间
  • 函数作为一等公民的概念
  • nonlocal
    关键字的作用

在实际开发中,闭包常用于:

  • 创建配置化函数
  • 实现回调函数
  • 构建装饰器
  • 管理状态和上下文

通过合理使用闭包,可以编写出更加模块化、可重用和表达力强的代码。但同时也要注意闭包可能带来的内存管理和变量捕获问题,确保代码的健壮性和可维护性。

最新文章

随机文章

基本 文件 流程 错误 SQL 调试
  1. 请求信息 : 2026-07-02 23:26:20 HTTP/2.0 GET : https://f.mffb.com.cn/a/496178.html
  2. 运行时间 : 0.265863s [ 吞吐率:3.76req/s ] 内存消耗:4,633.05kb 文件加载:140
  3. 缓存信息 : 0 reads,0 writes
  4. 会话信息 : SESSION_ID=bb5f37957ffca25a5d0df37bcc210b0c
  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.000644s ] mysql:host=127.0.0.1;port=3306;dbname=f_mffb;charset=utf8mb4
  2. SHOW FULL COLUMNS FROM `fenlei` [ RunTime:0.000877s ]
  3. SELECT * FROM `fenlei` WHERE `fid` = 0 [ RunTime:0.017333s ]
  4. SELECT * FROM `fenlei` WHERE `fid` = 63 [ RunTime:0.025768s ]
  5. SHOW FULL COLUMNS FROM `set` [ RunTime:0.000854s ]
  6. SELECT * FROM `set` [ RunTime:0.018038s ]
  7. SHOW FULL COLUMNS FROM `article` [ RunTime:0.000827s ]
  8. SELECT * FROM `article` WHERE `id` = 496178 LIMIT 1 [ RunTime:0.022864s ]
  9. UPDATE `article` SET `lasttime` = 1783005980 WHERE `id` = 496178 [ RunTime:0.005769s ]
  10. SELECT * FROM `fenlei` WHERE `id` = 66 LIMIT 1 [ RunTime:0.005833s ]
  11. SELECT * FROM `article` WHERE `id` < 496178 ORDER BY `id` DESC LIMIT 1 [ RunTime:0.010530s ]
  12. SELECT * FROM `article` WHERE `id` > 496178 ORDER BY `id` ASC LIMIT 1 [ RunTime:0.009083s ]
  13. SELECT * FROM `article` WHERE `id` < 496178 ORDER BY `id` DESC LIMIT 10 [ RunTime:0.025457s ]
  14. SELECT * FROM `article` WHERE `id` < 496178 ORDER BY `id` DESC LIMIT 10,10 [ RunTime:0.016429s ]
  15. SELECT * FROM `article` WHERE `id` < 496178 ORDER BY `id` DESC LIMIT 20,10 [ RunTime:0.035521s ]
0.267503s