当前位置:首页>python>Python的Litestar库介绍

Python的Litestar库介绍

  • 2026-03-27 23:34:53
Python的Litestar库介绍

Litestar是一个功能强大、性能优异的现代Python ASGI框架,专注于构建API。它充分利用了Python的类型提示系统,提供自动数据验证、序列化/反序列化以及OpenAPI文档生成。下面通过大量代码来展示它的核心特性。

安装和Hello World

首先通过pip安装Litestar。如果加上standard选项,会同时安装uvicorn服务器和CLI工具:

pip install 'litestar[standard]'

创建一个最简单的应用,保存为app.py:

from litestar import Litestar, get@get("/")async def hello_world() -> dict[strstr]:    """传统的Hello World示例"""    return {"hello""world"}app = Litestar(route_handlers=[hello_world])

然后在终端运行:

litestar run# 或带自动重载的开发模式litestar run --reload

访问 http://127.0.0.1:8000/ 就能看到返回的JSON数据。

基于类的控制器

虽然Litestar支持函数式路由,但它也推荐使用类来组织相关的路由,让代码结构更清晰:

from typing import ListOptionalfrom datetime import datetimefrom uuid import UUIDfrom litestar import Controller, get, post, put, patch, deletefrom pydantic import BaseModel# 定义数据模型class User(BaseModel):    id: UUID    name: str    email: str    created_at: datetimeclass UserController(Controller):    path = "/users"  # 所有路由都以 /users 开头    @post()    async def create_user(self, data: User) -> User:        """创建新用户"""        # 在实际应用中,这里会保存到数据库        return data    @get()    async def list_users(self) -> List[User]:        """获取所有用户列表"""        return []    @get(path="/{user_id:uuid}")    async def get_user(self, user_id: UUID) -> Optional[User]:        """根据ID获取单个用户"""        # user_id 会自动从URL路径中解析并验证        return None    @get(path="/search/{name:str}")    async def search_users_by_name(self, name: str) -> List[User]:        """根据名字搜索用户"""        return []    @put(path="/{user_id:uuid}")    async def update_user(self, user_id: UUID, data: User) -> User:        """完整更新用户信息"""        return data    @patch(path="/{user_id:uuid}")    async def partial_update_user(self, user_id: UUID, data: dict) -> User:        """部分更新用户信息"""        return User(**data)    @delete(path="/{user_id:uuid}")    async def delete_user(self, user_id: UUID) -> None:        """删除用户"""        return None# 注册控制器app = Litestar(route_handlers=[UserController])

通过类型注解,Litestar能自动完成参数验证、序列化和OpenAPI文档生成。路径参数如{user_id:uuid}会自动进行类型转换和验证。

依赖注入系统

Litestar的依赖注入系统受pytest启发,非常灵活。你可以定义同步或异步的依赖,并在应用的不同层级复用:

from litestar import Litestar, getfrom litestar.di import Providefrom litestar.datastructures import Stateimport random# 定义依赖函数async def get_user_id() -> str:    """模拟从请求头或token中获取用户ID"""    return f"user_{random.randint(10009999)}"async def get_database_connection(state: State) -> dict:    """获取数据库连接(从应用状态中获取配置)"""    # 模拟数据库连接    return {"connection""active""config"getattr(state, "db_config""default")}async def get_current_user(    user_id: str,  # 这个参数会从上一个依赖注入    db: dict       # 这个也是) -> dict:    """获取当前用户信息"""    return {        "id": user_id,        "name"f"User_{user_id}",        "db_status": db.get("connection")    }# 使用依赖的路由@get("/me")async def get_me(    current_user: dict,  # 这个参数会被注入    db: dict            # 这个也会) -> dict:    """获取当前用户信息"""    return {        "user": current_user,        "database": db    }@get("/health")async def health_check(db: dict) -> dict:    """健康检查端点"""    return {"status""ok""database": db["connection"]}# 注册依赖app = Litestar(    route_handlers=[get_me, health_check],    dependencies={        "user_id": Provide(get_user_id),        "db": Provide(get_database_connection),        "current_user": Provide(get_current_user)    },    state={"db_config""postgresql://localhost/mydb"}  # 应用状态)

依赖可以相互注入,Litestar会自动解析依赖图。

路由守卫(授权机制)

Guards是Litestar的授权机制,可以在请求到达路由处理器之前进行验证:

from litestar import Litestar, getfrom litestar.connection import ASGIConnectionfrom litestar.handlers.base import BaseRouteHandlerfrom litestar.exceptions import NotAuthorizedExceptionfrom litestar.di import Provide# 定义守卫函数async def require_auth(connection: ASGIConnection, handler: BaseRouteHandler) -> None:    """验证用户是否已认证"""    auth_header = connection.headers.get("Authorization")    if not auth_header or not auth_header.startswith("Bearer "):        raise NotAuthorizedException("Missing or invalid authorization token")    # 在实际应用中,这里会验证token并可能将用户信息存入connection    token = auth_header.split(" ")[1]    if token != "secret-token":        raise NotAuthorizedException("Invalid token")async def require_admin(connection: ASGIConnection, handler: BaseRouteHandler) -> None:    """验证用户是否有管理员权限"""    # 假设从某处获取用户角色    user_role = connection.headers.get("X-User-Role")    if user_role != "admin":        raise NotAuthorizedException("Admin privileges required")# 应用守卫@get("/public")async def public_endpoint() -> dict:    """公开端点,不需要认证"""    return {"message""This is public"}@get("/protected", guards=[require_auth])async def protected_endpoint() -> dict:    """需要认证的端点"""    return {"message""You are authenticated"}@get("/admin", guards=[require_auth, require_admin])async def admin_endpoint() -> dict:    """需要认证且是管理员"""    return {"message""Welcome admin"}app = Litestar(route_handlers=[public_endpoint, protected_endpoint, admin_endpoint])

守卫可以应用于单个路由、整个控制器或整个应用,并且支持多个守卫组合。

WebSocket和实时通信

Litestar对WebSocket有良好的支持,可以轻松实现实时通信功能。下面的例子展示了一个简单的聊天室:

from contextlib import asynccontextmanagerfrom typing import AsyncContextManagerfrom litestar import Litestar, WebSocketfrom litestar.channels import ChannelsPluginfrom litestar.channels.backends.memory import MemoryChannelsBackendfrom litestar.exceptions import WebSocketDisconnectfrom litestar.handlers import websocket_listener@asynccontextmanagerasync def chat_room_lifespan(    socket: WebSocket,     channels: ChannelsPlugin) -> AsyncContextManager[None]:    """管理WebSocket连接的生命周期"""    # 订阅聊天频道,历史消息保留10条    async with channels.start_subscription("chat", history=10as subscriber:        try:            # 在后台运行消息发送任务            async with subscriber.run_in_background(socket.send_data):                yield        except WebSocketDisconnect:            # 客户端断开连接时正常退出            return@websocket_listener("/ws/chat", connection_lifespan=chat_room_lifespan)async def chat_handler(data: str, channels: ChannelsPlugin) -> None:    """处理收到的聊天消息并广播给所有订阅者"""    # 将消息发布到chat频道    channels.publish(data, channels=["chat"])# 创建应用并注册channels插件app = Litestar(    route_handlers=[chat_handler],    plugins=[        ChannelsPlugin(            channels=["chat"],            backend=MemoryChannelsBackend(history=10)        )    ])

配合前端HTML代码,只需要几十行代码就能实现一个完整的聊天室应用,支持消息广播和历史消息重放。

应用生命周期管理

Litestar提供了多种方式管理应用的启动和关闭,这对于处理数据库连接、缓存客户端等资源非常有用:

from contextlib import asynccontextmanagerfrom typing import AsyncGeneratorfrom litestar import Litestar, getfrom litestar.datastructures import Stateimport asyncpg# 方式1:使用 on_startup 和 on_shutdown 钩子async def setup_database(app: Litestar) -> None:    """在应用启动时建立数据库连接"""    # 创建数据库连接池    pool = await asyncpg.create_pool(        "postgresql://user:pass@localhost/db",        min_size=1,        max_size=10    )    app.state.db_pool = pool    print("Database connected")async def cleanup_database(app: Litestar) -> None:    """在应用关闭时清理数据库连接"""    if hasattr(app.state, "db_pool"):        await app.state.db_pool.close()        print("Database disconnected")# 方式2:使用 lifespan 上下文管理器(推荐)@asynccontextmanagerasync def redis_connection(app: Litestar) -> AsyncGenerator[NoneNone]:    """使用上下文管理器管理Redis连接"""    import redis.asyncio as redis    # 建立连接    client = redis.from_url("redis://localhost", decode_responses=True)    app.state.redis = client    print("Redis connected")    try:        yield  # 应用运行期间    finally:        # 关闭连接        await client.close()        print("Redis disconnected")@get("/users/count")async def get_users_count(state: State) -> dict:    """使用数据库连接的示例端点"""    if hasattr(state, "db_pool"):        async with state.db_pool.acquire() as conn:            count = await conn.fetchval("SELECT COUNT(*) FROM users")            return {"count": count}    return {"error""Database not available"}@get("/cache/test")async def cache_test(state: State) -> dict:    """使用Redis缓存的示例端点"""    if hasattr(state, "redis"):        await state.redis.set("test_key""Hello Redis")        value = await state.redis.get("test_key")        return {"cached": value}    return {"error""Redis not available"}# 可以同时使用多种生命周期管理方式app = Litestar(    route_handlers=[get_users_count, cache_test],    on_startup=[setup_database],      # 启动时执行    on_shutdown=[cleanup_database],   # 关闭时执行    lifespan=[redis_connection]       # 使用上下文管理器)

当同时使用多个lifespan上下文管理器时,它们会按照声明的顺序进入,逆序退出。

应用状态管理

Litestar的State对象提供了一种在应用各组件之间共享数据的机制:

from litestar import Litestar, getfrom litestar.datastructures import State, ImmutableStatefrom litestar.di import Provide# 使用自定义状态类class AppState:    def __init__(self):        self.startup_time = None        self.request_count = 0        self.config = {}    def increment_count(self):        self.request_count += 1@get("/stats")async def get_stats(state: State) -> dict:    """获取应用统计信息"""    if hasattr(state, "app_state"):        app_state = state.app_state        return {            "request_count": app_state.request_count,            "startup_time": app_state.startup_time,            "config": app_state.config        }    return {"error""State not initialized"}@get("/increment")async def increment(state: State) -> dict:    """增加请求计数"""    if hasattr(state, "app_state"):        state.app_state.increment_count()        return {"count": state.app_state.request_count}    return {"error""State not initialized"}# 初始化应用状态initial_state = AppState()initial_state.startup_time = "2024-01-01T00:00:00"initial_state.config = {"debug"True"version""1.0.0"}app = Litestar(    route_handlers=[get_stats, increment],    state=State({"app_state": initial_state})  # 使用State包装自定义对象)# 如果想使用不可变状态,防止意外修改# from litestar.datastructures import ImmutableState# app = Litestar(route_handlers=[...], state=ImmutableState({"key": "value"}))

状态对象可以通过依赖注入或直接在路由处理器中访问。

中间件

Litestar内置了多种常用中间件,也可以自定义中间件:

from litestar import Litestar, getfrom litestar.middleware.cors import CORSMiddlewarefrom litestar.middleware.rate_limit import RateLimitMiddlewarefrom litestar.middleware.session import SessionMiddleware, ServerSideSessionConfigfrom litestar.middleware.base import AbstractMiddlewarefrom litestar.types import ASGIApp, Receive, Scope, Sendimport time# 自定义中间件:记录请求处理时间class TimingMiddleware(AbstractMiddleware):    async def __call__(self, scope: Scope, receive: Receive, send: Send) -> None:        if scope["type"] == "http":            start_time = time.time()            # 创建一个包装的send函数来捕获响应时间            async def timing_send(message):                if message["type"] == "http.response.start":                    elapsed = time.time() - start_time                    # 可以在这里记录到日志                    print(f"Request to {scope['path']} took {elapsed:.3f}s")                await send(message)            await self.app(scope, receive, timing_send)        else:            await self.app(scope, receive, send)@get("/")async def index() -> dict:    return {"message""Hello"}@get("/slow")async def slow() -> dict:    """模拟慢请求"""    import asyncio    await asyncio.sleep(2)    return {"message""Done"}app = Litestar(    route_handlers=[index, slow],    middleware=[        TimingMiddleware,  # 自定义中间件        CORSMiddleware,    # 跨域资源共享        RateLimitMiddleware,  # 速率限制    ],    cors_config={        "allow_origins": ["http://localhost:3000"],        "allow_methods": ["GET""POST""PUT""DELETE"],        "allow_headers": ["Content-Type""Authorization"]    },    rate_limit_config={        "rate_limit": ("minute"100),  # 每分钟最多100个请求        "exclude": ["/health"]  # 排除健康检查端点    })

内置中间件包括CORS、CSRF、速率限制、GZip压缩、会话管理等。

小结

Litestar是一个功能完善的ASGI框架,核心优势包括:

强类型驱动:充分利用Python类型提示,提供自动验证和OpenAPI文档

高性能:基于msgspec进行超快序列化,性能优异

依赖注入:灵活强大的DI系统,便于测试和代码组织

完整的WebSocket支持:内置channels模块,支持消息广播和持久化

生产就绪:提供CORS、速率限制、会话管理等生产环境所需的功能

可扩展:插件系统支持SQLAlchemy等ORM的无缝集成

适合构建从简单API到复杂全栈应用的各类项目。建议从官方文档和示例项目(如litestar-fullstack)开始学习实践。

最新文章

随机文章

基本 文件 流程 错误 SQL 调试
  1. 请求信息 : 2026-03-28 14:29:07 HTTP/2.0 GET : https://f.mffb.com.cn/a/483477.html
  2. 运行时间 : 0.169853s [ 吞吐率:5.89req/s ] 内存消耗:4,855.14kb 文件加载:140
  3. 缓存信息 : 0 reads,0 writes
  4. 会话信息 : SESSION_ID=c68628a7b654519946b57dfa97c1457c
  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.000388s ] mysql:host=127.0.0.1;port=3306;dbname=f_mffb;charset=utf8mb4
  2. SHOW FULL COLUMNS FROM `fenlei` [ RunTime:0.000551s ]
  3. SELECT * FROM `fenlei` WHERE `fid` = 0 [ RunTime:0.000276s ]
  4. SELECT * FROM `fenlei` WHERE `fid` = 63 [ RunTime:0.000264s ]
  5. SHOW FULL COLUMNS FROM `set` [ RunTime:0.000461s ]
  6. SELECT * FROM `set` [ RunTime:0.000241s ]
  7. SHOW FULL COLUMNS FROM `article` [ RunTime:0.000543s ]
  8. SELECT * FROM `article` WHERE `id` = 483477 LIMIT 1 [ RunTime:0.012052s ]
  9. UPDATE `article` SET `lasttime` = 1774679347 WHERE `id` = 483477 [ RunTime:0.002994s ]
  10. SELECT * FROM `fenlei` WHERE `id` = 66 LIMIT 1 [ RunTime:0.000613s ]
  11. SELECT * FROM `article` WHERE `id` < 483477 ORDER BY `id` DESC LIMIT 1 [ RunTime:0.000526s ]
  12. SELECT * FROM `article` WHERE `id` > 483477 ORDER BY `id` ASC LIMIT 1 [ RunTime:0.000459s ]
  13. SELECT * FROM `article` WHERE `id` < 483477 ORDER BY `id` DESC LIMIT 10 [ RunTime:0.001039s ]
  14. SELECT * FROM `article` WHERE `id` < 483477 ORDER BY `id` DESC LIMIT 10,10 [ RunTime:0.010091s ]
  15. SELECT * FROM `article` WHERE `id` < 483477 ORDER BY `id` DESC LIMIT 20,10 [ RunTime:0.062890s ]
0.173710s