ka4ivan/laravel-api-debugger 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

ka4ivan/laravel-api-debugger

Composer 安装命令:

composer require ka4ivan/laravel-api-debugger

包简介

A debugging tool for Laravel APIs that provides request execution time and query profiling.

README 文档

README

License Build Status Latest Stable Version Total Downloads Quality Score

Installation

  1. Require this package with composer
composer require ka4ivan/laravel-api-debugger --dev
  1. Debug works if the APP_DEBUG = true

How it works

  • The debugger will start logging SQL queries and request data for every API request.
  • It will only activate if APP_DEBUG=true in your .env file.
  • The results, including query count, execution time, and detailed data, will be attached to the API response for debugging purposes.

Example

When you send an API request and APP_DEBUG=true, you'll receive the following debug data in the response:

{
    "data": {
        "..."
    },
    "debugger": {
        "queries": {
            "count": 8,
            "time": 14.57,
            "data": [
                {
                    "sql": "select * from `domains` where `is_active` = ? limit 1",
                    "bindings": [true],
                    "time": 10.09,
                    "trace": [
                        "/var/www/html/app/Support/Domains/Domain.php:101",
                        "/var/www/html/app/Http/Middleware/SetClientDomain.php:32",
                        "/var/www/html/public/index.php:51"
                    ]
                },
                {
                    "sql": "select * from `products` limit 1",
                    "bindings": [],
                    "time": 0.75,
                    "trace": [
                        "/var/www/html/app/Http/Controllers/ProductController.php:27",
                        "/var/www/html/public/index.php:51"
                    ]
                },
                {
                    "sql": "select * from `menu_items` where (`domain_id` = ? or `domain_id` is null) order by `weight` asc",
                    "bindings": ["8e591823-4f64-4e90-b564-e0c090696d6e"],
                    "time": 0.82,
                    "trace": [
                        "/var/www/html/app/Support/Menu/MenuLoader.php:17",
                        "/var/www/html/public/index.php:51"
                    ]
                },
                {
                    "sql": "select * from `pages` where `slug` = ? and (`domain_id` = ? or `domain_id` is null) and `status` = ? order by `weight` asc, `created_at` asc limit 1",
                    "bindings": ["contacts", "8e591823-4f64-4e90-b564-e0c090696d6e", "published"],
                    "time": 0.76,
                    "trace": [
                        "/var/www/html/app/Support/Pages/PageService.php:89",
                        "/var/www/html/public/index.php:51"
                    ]
                },
                {
                    "sql": "select * from `comparisons` where `guest_id` = ?",
                    "bindings": ["62afacc1-37b2-464d-8028-818745e56de5"],
                    "time": 0.61,
                    "trace": [
                        "/var/www/html/app/Http/Middleware/ComparisonMiddleware.php:19",
                        "/var/www/html/public/index.php:51"
                    ]
                },
                {
                    "sql": "select * from `comparisons` where `guest_id` = ?",
                    "bindings": ["62afacc1-37b2-464d-8028-818745e56de5"],
                    "time": 0.61,
                    "trace": [
                        "/var/www/html/app/Http/Middleware/ComparisonMiddleware.php:20",
                        "/var/www/html/public/index.php:51"
                    ]
                },
                {
                    "sql": "select * from `comparisons` where `guest_id` = ?",
                    "bindings": ["62afacc1-37b2-464d-8028-818745e56de5"],
                    "time": 0.63,
                    "trace": [
                        "/var/www/html/app/Http/Middleware/ComparisonMiddleware.php:21",
                        "/var/www/html/public/index.php:51"
                    ]
                },
                {
                    "sql": "select * from `seos` where `path` = ? limit 1",
                    "bindings": [""],
                    "time": 0.93,
                    "trace": [
                        "/var/www/html/app/Http/Controllers/SeoController.php:14",
                        "/var/www/html/public/index.php:51"
                    ]
                }
            ],
            "long_queries": [
                {
                    "query": "select * from `domains` where `is_active` = ? limit 1",
                    "bindings": [
                        true
                    ],
                    "time": 10.09,
                    "trace": [
                        "/var/www/html/app/Support/Domains/Domain.php:101",
                        "/var/www/html/app/Http/Middleware/SetClientDomain.php:32",
                        "/var/www/html/public/index.php:51"
                    ]
                }
            ],
            "repeated_queries": [
                {
                    "query": "select * from `comparisons` where `guest_id` = ?",
                    "count": 3,
                    "backtrace": [
                          [
                              "/var/www/html/app/Http/Middleware/ComparisonMiddleware.php:19",
                              "/var/www/html/public/index.php:51"
                          ],
                          [
                              "/var/www/html/app/Http/Middleware/ComparisonMiddleware.php:20",
                              "/var/www/html/public/index.php:51"
                          ],
                          [
                              "/var/www/html/app/Http/Middleware/ComparisonMiddleware.php:21",
                              "/var/www/html/public/index.php:51"
                          ]
                      ]
                }
            ]
        },
        "request": {
            "body": [],
            "headers": {
                "connection": [
                    "keep-alive"
                ],
                "accept-encoding": [
                    "gzip, deflate, br"
                ],
                "host": [
                    "dev-packages.test"
                ],
                "postman-token": [
                    "8654756-6abf-4511-9b91-72865463"
                ],
                "user-agent": [
                    "PostmanRuntime/7.37.3"
                ],
                "authorization": [
                    "Bearer 8|vxwhATRrOfinZiR4zvhoTpckGqYJTPnmj9tkOfdMb5d9da28"
                ],
                "accept": [
                    "application/json"
                ]
            }
        }
    }
}

License

This package is licensed under the MIT License. You can freely use, modify, and distribute this package, provided that you include a copy of the license in any redistributed software.

统计信息

  • 总下载量: 795
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 6
  • 点击次数: 3
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 6
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-02-25

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固