当前位置:首页>python>Python 设计模式:解释器模式——让代码读懂你的语言

Python 设计模式:解释器模式——让代码读懂你的语言

  • 2026-07-02 16:42:53
Python 设计模式:解释器模式——让代码读懂你的语言

你有没有想过,计算器是如何解析并执行 1 + 2 * (3 - 4) 这样的表达式的?或者 SQL 引擎是如何理解 SELECT * FROM users WHERE age > 18 这样的语句的?

这些看似复杂的"语言理解"能力,背后其实都是解释器模式(Interpreter Pattern) 在支撑。它定义了一种语法表示,并提供一个解释器来处理这种语法。

在 Python 中,解释器模式并不常见,但当你需要解析特定领域的语言(DSL)、配置文件、数学表达式,甚至自定义规则引擎时,它就是一种优雅而强大的选择。

今天我们就来深入理解这个"让代码读懂你语言"的设计模式。


一、什么是解释器模式

解释器模式(Interpreter Pattern)
 是一种行为型设计模式,它定义了一种语言的文法表示,并定义一个解释器来解释该语言中的句子。

为什么需要解释器模式

假设你在开发一个电商系统,需要支持灵活的促销规则:

  • "订单金额满 100 减 20"
  • "会员等级为 VIP 且订单金额满 500,打 8 折"
  • "新用户首单免邮费,或订单金额满 99 免邮"

如果这些规则硬编码在代码里,每次调整规则都需要修改源码、重新部署。更好的做法是——让运营人员通过一段简单的规则语言来描述促销逻辑,由程序来解析和执行。

这就是解释器模式的应用场景:当有一个简单语言需要解释执行,且文法规则相对固定时,为语言创建解释器。

解释器模式的结构

解释器模式包含以下核心角色:

  1. 抽象表达式(Abstract Expression):定义解释器的接口,包含 interpret() 方法
  2. 终结符表达式(Terminal Expression):实现与文法中的终结符相关的解释操作,比如变量、常量
  3. 非终结符表达式(Non-terminal Expression):实现与文法中的非终结符相关的解释操作,比如加法、减法、逻辑与/或
  4. 上下文(Context):包含解释器之外的一些全局信息
  5. 客户端(Client):构建抽象语法树(AST),并调用解释器执行

二、实战:从零实现一个规则引擎

让我们通过一个非常贴近实际的案例来理解解释器模式——实现一个支持基本运算和逻辑判断的规则引擎。

2.1 定义表达式接口

from abc import ABC, abstractmethodclass Expression(ABC):    """抽象表达式——所有表达式的基础接口"""    @abstractmethod    def interpret(self, context):        """解释表达式,返回结果"""        pass

2.2 实现终结符表达式

终结符表达式是最基础的表达式,它们不再包含子表达式:

class NumberExpression(Expression):    """数字常量——终结符表达式"""    def __init__(self, value):        self.value = float(value)    def interpret(self, context):        return self.valueclass VariableExpression(Expression):    """变量引用——终结符表达式"""    def __init__(self, name):        self.name = name    def interpret(self, context):        if self.name not in context:            raise ValueError(f"变量 '{self.name}' 未定义")        return context[self.name]

2.3 实现非终结符表达式

非终结符表达式由子表达式组合而成:

class AddExpression(Expression):    """加法表达式——非终结符表达式"""    def __init__(self, left, right):        self.left = left        self.right = right    def interpret(self, context):        return self.left.interpret(context) + self.right.interpret(context)class SubtractExpression(Expression):    """减法表达式"""    def __init__(self, left, right):        self.left = left        self.right = right    def interpret(self, context):        return self.left.interpret(context) - self.right.interpret(context)class MultiplyExpression(Expression):    """乘法表达式"""    def __init__(self, left, right):        self.left = left        self.right = right    def interpret(self, context):        return self.left.interpret(context) * self.right.interpret(context)class GreaterThanExpression(Expression):    """大于比较表达式"""    def __init__(self, left, right):        self.left = left        self.right = right    def interpret(self, context):        return self.left.interpret(context) > self.right.interpret(context)class AndExpression(Expression):    """逻辑与表达式"""    def __init__(self, left, right):        self.left = left        self.right = right    def interpret(self, context):        return self.left.interpret(context) and self.right.interpret(context)class OrExpression(Expression):    """逻辑或表达式"""    def __init__(self, left, right):        self.left = left        self.right = right    def interpret(self, context):        return self.left.interpret(context) or self.right.interpret(context)

2.4 构建规则并执行

# 构建规则:订单金额 > 100 AND 会员等级 == "VIP"# AST: AndExpression(#        GreaterThanExpression(Variable("amount"), Number(100)),#        EqualExpression(Variable("level"), String("VIP"))#      )rule = AndExpression(    GreaterThanExpression(        VariableExpression("amount"),        NumberExpression(100)    ),    EqualExpression(        VariableExpression("level"),        StringExpression("VIP")    ))# 提供上下文(变量值)context1 = {"amount": 150, "level""VIP"}print(rule.interpret(context1))  # Truecontext2 = {"amount": 150, "level""NORMAL"}print(rule.interpret(context2))  # Falsecontext3 = {"amount": 50, "level""VIP"}print(rule.interpret(context3))  # False

关键设计要点

  • Expressio 是抽象基类,定义了统一的 interpret() 接口
  • NumberExpression、VariableExpression 是终结符,直接返回值
  • AddExpression、AndExpression 等是非终结符,递归调用子表达式的 interpret()
  • 上下文 context 是一个字典,存储变量名到值的映射

三、进阶:实现一个真正的解析器

上面的例子中,我们手动构建了抽象语法树(AST)。但在实际应用中,用户输入的是字符串,比如 "amount > 100 AND level == 'VIP'"。我们需要一个解析器将字符串转换为 AST。

3.1 词法分析(Tokenizer)

首先将字符串切分为一个个"词法单元"(Token):

import refrom enum import Enum, autoclass TokenType(Enum):    NUMBER = auto()    STRING = auto()    VARIABLE = auto()    PLUS = auto()    MINUS = auto()    MULTIPLY = auto()    GREATER_THAN = auto()    EQUAL = auto()    AND = auto()    OR = auto()    LPAREN = auto()    RPAREN = auto()    EOF = auto()class Token:    def __init__(self, type_, value):        self.type = type_        self.value = value    def __repr__(self):        return f"Token({self.type}{self.value!r})"def tokenize(expression):    """词法分析:将字符串拆分为 Token 列表"""    tokens = []    pos = 0    patterns = [        (r"\s+"None),  # 跳过空白        (r"\d+(?:\.\d+)?", TokenType.NUMBER),        (r"'[^']*'|\"[^\"]*\"", TokenType.STRING),        (r"[a-zA-Z_]\w*", TokenType.VARIABLE),        (r"\+", TokenType.PLUS),        (r"-", TokenType.MINUS),        (r"\*", TokenType.MULTIPLY),        (r">", TokenType.GREATER_THAN),        (r"==", TokenType.EQUAL),        (r"AND", TokenType.AND),        (r"OR", TokenType.OR),        (r"\(", TokenType.LPAREN),        (r"\)", TokenType.RPAREN),    ]    while pos < len(expression):        match = None        for pattern, token_type in patterns:            regex = re.compile(pattern)            match = regex.match(expression, pos)            if match:                if token_type:  # 不是空白                    value = match.group(0)                    # 去掉字符串引号                    if token_type == TokenType.STRING:                        value = value[1:-1]                    tokens.append(Token(token_type, value))                pos = match.end()                break        if not match:            raise ValueError(f"无法识别的字符: {expression[pos]}")    tokens.append(Token(TokenType.EOF, None))    return tokens

3.2 语法分析(Parser)

将 Token 列表转换为 AST:

class Parser:    """语法分析器:将 Token 列表转换为 AST"""    def __init__(self, tokens):        self.tokens = tokens        self.pos = 0    def current(self):        return self.tokens[self.pos]    def advance(self):        token = self.current()        self.pos += 1        return token    def expect(self, token_type):        if self.current().type != token_type:            raise ValueError(f"期望 {token_type},但得到 {self.current().type}")        return self.advance()    def parse(self):        """解析入口"""        return self.parse_or()    def parse_or(self):        """OR 表达式"""        node = self.parse_and()        while self.current().type == TokenType.OR:            self.advance()            right = self.parse_and()            node = OrExpression(node, right)        return node    def parse_and(self):        """AND 表达式"""        node = self.parse_comparison()        while self.current().type == TokenType.AND:            self.advance()            right = self.parse_comparison()            node = AndExpression(node, right)        return node    def parse_comparison(self):        """比较表达式"""        node = self.parse_additive()        if self.current().type == TokenType.GREATER_THAN:            self.advance()            right = self.parse_additive()            return GreaterThanExpression(node, right)        elif self.current().type == TokenType.EQUAL:            self.advance()            right = self.parse_additive()            return EqualExpression(node, right)        return node    def parse_additive(self):        """加减法表达式"""        node = self.parse_multiplicative()        while self.current().type in (TokenType.PLUS, TokenType.MINUS):            if self.current().type == TokenType.PLUS:                self.advance()                right = self.parse_multiplicative()                node = AddExpression(node, right)            else:                self.advance()                right = self.parse_multiplicative()                node = SubtractExpression(node, right)        return node    def parse_multiplicative(self):        """乘除法表达式"""        node = self.parse_primary()        while self.current().type == TokenType.MULTIPLY:            self.advance()            right = self.parse_primary()            node = MultiplyExpression(node, right)        return node    def parse_primary(self):        """基础表达式:数字、变量、括号"""        token = self.current()        if token.type == TokenType.NUMBER:            self.advance()            return NumberExpression(float(token.value))        elif token.type == TokenType.STRING:            self.advance()            return StringExpression(token.value)        elif token.type == TokenType.VARIABLE:            self.advance()            return VariableExpression(token.value)        elif token.type == TokenType.LPAREN:            self.advance()            node = self.parse_or()            self.expect(TokenType.RPAREN)            return node        raise ValueError(f"意外的 Token: {token}")

3.3 完整使用流程

def evaluate(expression, context):    """评估表达式字符串"""    tokens = tokenize(expression)    parser = Parser(tokens)    ast = parser.parse()    return ast.interpret(context)# 使用示例context = {"amount"150"level""VIP""is_new"False}result1 = evaluate("amount > 100 AND level == 'VIP'", context)print(result1)  # Trueresult2 = evaluate("(amount - 50) * 2 > 100 OR is_new == True", context)print(result2)  # Trueresult3 = evaluate("amount + 50 > 300", context)print(result3)  # False

四、Pythonic 的替代方案:eval 与 ast 模块

虽然解释器模式优雅,但 Python 本身提供了强大的动态执行能力。在某些场景下,使用内置功能可能是更好的选择。

4.1 使用 eval()(简单但危险)

context = {"amount": 150, "level""VIP"}# 极度危险!不要直接使用用户输入的字符串expression = "amount > 100 and level == 'VIP'"result = eval(expression, {"__builtins__": {}}, context)print(result)  # True

警告eval() 执行任意代码,如果表达式来自用户输入,存在严重的安全风险。仅用于完全受信任的内部场景。

4.2 使用 ast 模块(安全推荐)

Python 的 ast 模块可以将表达式解析为 AST,然后你可以安全地遍历和求值:

import astimport operatorclass SafeEvaluator(ast.NodeVisitor):    """安全的表达式求值器"""    # 支持的操作符    operators = {        ast.Add: operator.add,        ast.Sub: operator.sub,        ast.Mult: operator.mul,        ast.Div: operator.truediv,        ast.Gt: operator.gt,        ast.Lt: operator.lt,        ast.Eq: operator.eq,        ast.And: lambda a, b: a and b,        ast.Or: lambda a, b: a or b,    }    def __init__(self, context):        self.context = context    def visit_Constant(self, node):        return node.value    def visit_Name(self, node):        if node.id not in self.context:            raise NameError(f"变量 '{node.id}' 未定义")        return self.context[node.id]    def visit_BinOp(self, node):        left = self.visit(node.left)        right = self.visit(node.right)        op_type = type(node.op)        if op_type not in self.operators:            raise ValueError(f"不支持的操作符: {op_type}")        return self.operators[op_type](left, right)    def visit_BoolOp(self, node):        values = [self.visit(v) for v in node.values]        op_type = type(node.op)        if op_type not in self.operators:            raise ValueError(f"不支持的操作符: {op_type}")        result = values[0]        for v in values[1:]:            result = self.operators[op_type](result, v)        return result    def visit_Compare(self, node):        left = self.visit(node.left)        for op, comparator in zip(node.ops, node.comparators):            right = self.visit(comparator)            op_type = type(op)            if op_type not in self.operators:                raise ValueError(f"不支持的操作符: {op_type}")            if not self.operators[op_type](left, right):                return False            left = right        return True    def evaluate(self, expression):        tree = ast.parse(expression, mode="eval")        return self.visit(tree.body)# 使用evaluator = SafeEvaluator({"amount"150"level""VIP"})result = evaluator.evaluate("amount > 100 and level == 'VIP'")print(result)  # True

使用 ast 模块的优势:

  • 安全性:只允许你明确支持的操作,拒绝任何危险代码
  • 灵活性:可以扩展支持自定义函数和变量
  • 与 Python 语法一致:用户可以直接使用熟悉的 Python 表达式

4.3 什么时候用手写解释器,什么时候用 ast

场景
推荐方案
简单规则,安全性要求高
ast
 模块 + 安全求值器
需要完全自定义语法(非 Python 语法)
手写解释器模式
复杂语言,需要完善错误报告
手写解释器 + 专门的解析器生成器(如 PLY、Lark)
内部工具,完全受信任的输入
eval()
(仍需限制 builtins)

五、解释器模式的应用场景

场景 1:业务规则引擎

电商、金融系统中的促销规则、风控规则、审批规则,通常需要灵活配置:

# 风控规则:交易额 > 10000 AND (用户信用分 < 600 OR 用户状态 == "高风险")rule = "amount > 10000 and (credit_score < 600 or status == '高风险')"result = evaluate(rule, context)

场景 2:配置文件解析

一些高级配置文件允许表达式,比如 Nginx、SQLAlchemy 的过滤条件:

# 伪代码示例[discount]rule = "member_level == 'gold' and order_amount >= 500"discount_rate = 0.8

场景 3:模板引擎

Jinja2、Django Template 等模板引擎的核心就是解释器模式——解析模板语法,替换变量,执行逻辑:

{% if user.is_vip and order.total > 100 %}    恭喜您享受 VIP 优惠!{% endif %}

场景 4:数学表达式计算

科学计算软件、Excel 公式解析器都是解释器模式的典型应用:

formula = "SUM(A1:A10) * 1.08 + IF(B1 > 100, 50, 0)"result = spreadsheet.evaluate(formula)

场景 5:自定义查询语言

为特定领域设计简化查询语言,比如日志查询:

status:404 AND path:/api/* AND time>2024-01-01

六、解释器模式的优缺点

优点

  • 易于扩展:新增语法规则只需新增一个表达式类
  • 职责分离:文法表示与解释执行分离,结构清晰
  • 灵活性:可在运行时组合表达式,实现动态逻辑

缺点

  • 性能问题:递归调用和大量对象创建可能带来性能开销
  • 复杂文法难以维护:当规则超过 10-15 条时,类数量爆炸,难以维护
  • 调试困难:AST 的调试和错误报告需要额外工作

七、最佳实践与注意事项

7.1 文法复杂度控制

解释器模式适合简单、稳定的文法。如果文法复杂且频繁变动,建议使用专业工具:

  • PLY(Python Lex-Yacc):经典的词法/语法分析器生成器
  • Lark:现代化、易用的解析库,支持 EBNF 文法
  • ANTLR:跨平台的解析器生成器,支持 Python
# 使用 Lark 快速实现解析器from lark import Lark, Transformergrammar = """    ?start: expr    ?expr: term         | expr "+" term   -> add         | expr "-" term   -> sub    ?term: factor         | term "*" factor -> mul    ?factor: NUMBER          -> number           | VARIABLE        -> variable           | "(" expr ")"    NUMBER: /\d+/    VARIABLE: /[a-zA-Z_]\w*/    %import common.WS    %ignore WS"""parser = Lark(grammar)tree = parser.parse("1 + 2 * (3 - 4)")

7.2 缓存编译结果

如果同一个表达式会被重复执行多次,缓存 AST 避免重复解析:

class RuleEngine:    def __init__(self):        self._cache = {}    def evaluate(self, expression, context):        if expression not in self._cache:            tokens = tokenize(expression)            parser = Parser(tokens)            self._cache[expression] = parser.parse()        return self._cache[expression].interpret(context)

7.3 错误处理与日志

手写解释器时,务必提供清晰的错误信息:

class ParseError(Exception):    def __init__(self, message, token, position):        self.token = token        self.position = position        super().__init__(f"{message} at position {position}{token}")

7.4 类型检查

在构建 AST 时进行类型检查,避免运行时错误:

class GreaterThanExpression(Expression):    def __init__(self, left, right):        self.left = left        self.right = right    def interpret(self, context):        left_val = self.left.interpret(context)        right_val = self.right.interpret(context)        if not isinstance(left_val, (intfloat)):            raise TypeError(f"> 操作符不支持类型 {type(left_val)}")        return left_val > right_val

八、总结

解释器模式是"让代码读懂你语言"的设计模式——通过定义文法和解释器,让程序能够解析并执行特定领域的语言。

回顾本文要点:

  1. 解释器模式的核心思想:定义语言的文法表示,提供解释器来解释语言中的句子
  2. 四个角色:抽象表达式定义接口,终结符表达式处理基础元素,非终结符表达式处理复合规则,上下文提供全局信息
  3. 手写解释器的完整流程:词法分析(Tokenizer)→ 语法分析(Parser)→ 构建 AST → 递归求值
  4. Pythonic 替代方案:ast 模块是更安全、更推荐的方式,适合解析类 Python 表达式
  5. 典型应用:业务规则引擎、配置文件解析、模板引擎、数学表达式计算、自定义查询语言
  6. 最佳实践:控制文法复杂度,使用 Lark/PLY 等专业工具处理复杂文法,缓存编译结果,提供清晰的错误信息

掌握了解释器模式,你就拥有了一种强大的武器——不仅可以理解现有的语言,还能为特定领域创造属于你自己的语言。


如果这篇文章对你有帮助,欢迎点赞、在看、转发,你的支持是我持续创作的动力!

最新文章

随机文章

基本 文件 流程 错误 SQL 调试
  1. 请求信息 : 2026-07-03 11:16:51 HTTP/2.0 GET : https://f.mffb.com.cn/a/494549.html
  2. 运行时间 : 0.097947s [ 吞吐率:10.21req/s ] 内存消耗:4,541.95kb 文件加载:140
  3. 缓存信息 : 0 reads,0 writes
  4. 会话信息 : SESSION_ID=eeec96e08b14a09a26ca79d423ba4eb7
  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.000586s ] mysql:host=127.0.0.1;port=3306;dbname=f_mffb;charset=utf8mb4
  2. SHOW FULL COLUMNS FROM `fenlei` [ RunTime:0.000797s ]
  3. SELECT * FROM `fenlei` WHERE `fid` = 0 [ RunTime:0.000333s ]
  4. SELECT * FROM `fenlei` WHERE `fid` = 63 [ RunTime:0.000283s ]
  5. SHOW FULL COLUMNS FROM `set` [ RunTime:0.000531s ]
  6. SELECT * FROM `set` [ RunTime:0.000241s ]
  7. SHOW FULL COLUMNS FROM `article` [ RunTime:0.000596s ]
  8. SELECT * FROM `article` WHERE `id` = 494549 LIMIT 1 [ RunTime:0.000533s ]
  9. UPDATE `article` SET `lasttime` = 1783048611 WHERE `id` = 494549 [ RunTime:0.000791s ]
  10. SELECT * FROM `fenlei` WHERE `id` = 66 LIMIT 1 [ RunTime:0.000258s ]
  11. SELECT * FROM `article` WHERE `id` < 494549 ORDER BY `id` DESC LIMIT 1 [ RunTime:0.000552s ]
  12. SELECT * FROM `article` WHERE `id` > 494549 ORDER BY `id` ASC LIMIT 1 [ RunTime:0.007169s ]
  13. SELECT * FROM `article` WHERE `id` < 494549 ORDER BY `id` DESC LIMIT 10 [ RunTime:0.006561s ]
  14. SELECT * FROM `article` WHERE `id` < 494549 ORDER BY `id` DESC LIMIT 10,10 [ RunTime:0.005900s ]
  15. SELECT * FROM `article` WHERE `id` < 494549 ORDER BY `id` DESC LIMIT 20,10 [ RunTime:0.001717s ]
0.099508s