tsaikoga/performance-printer

PerformancePrinter 是一个 Laravel 扩展包,用于打印每个请求的性能信息,以便于开发。

v1.1.2 2022-10-16 14:14 UTC

This package is auto-updated.

Last update: 2024-09-17 04:56:14 UTC


README

Stable Unstable License Laravel

Performance Printer 是一个 Laravel 扩展包,用于打印每个请求的性能信息,以便于开发。

require : Laravel/framework 5.5+

特性

  • 请求

显示请求方法、请求路径和请求体。

  • 文件

包含文件的数量

  • 查询

由请求生成的每个原始 SQL 以及其耗时。

SQL 的解释

请求的 SQL 数量

  • 响应

响应数据和其耗时。

用法

  1. 为开发环境安装包

稳定版本:

composer require tsaikoga/performance-printer --dev

不稳定版本:

composer require tsaikoga/performance-printer:dev-master --dev

可以为打印机添加自定义配置。

  1. 创建文件 config/performance_printer.php
<?php
return [
    // print request message
    'request' => true,

    // print response datas
    'response' => false,

    // included files count
    'included_files_count' => true,

    // print table Style
    'table_style' => 'default',

    // language: Only support English(en) and Chinese(cn) now
    'lang' => 'cn',

    'query' => [
        // print raw sql
        'raw_sql' => true,

        // print explain sql
        'explain' => true,

        // Same queries with different bindings are superimposed
        'unique_query' => true,

        // The connections
        'connections' => ['mysql'],
    ],

    // enable this package or disable it
    'enable' => true,

    // log
    'log' => [
        // is logging enable?
        'enable' => true,

        // The path that the log file stored
        'filepath' => '/tmp/performance_printer.log',
    ],
];
  1. .env 文件中,将 local 设置为应用程序环境
APP_ENV=local
  1. 运行服务器
php artisan serve

如果您使用 nginx 或 apache 作为服务器,请尝试在配置中启用消息记录器,您还可以自定义日志路径(默认路径:/tmp/performance_printer.log

tail -f /tmp/performance_printer.log

预览

打印结果

[ POST ] /api/user/login
[ Content-Type ] :  application/json
{
	"user": "12345678910",
	"password": "b49f16999ce2a0a0df9b6e0e66bd4f32"
}

[ Included Files Count ]  379

[ Total ] 2 queries and ran for 16.39 ms.
[ SQL ran for 11.56 ms ] RAW SQL: select * from `users` where `phone` = "12345678910" or `email` = "12345678910" limit 1

+----+-------------+-------+------------+------+--------------------+-----+---------+-----+------+----------+-------------+
| id | select_type | table | partitions | type | possible_keys      | key | key_len | ref | rows | filtered | Extra       |
+----+-------------+-------+------------+------+--------------------+-----+---------+-----+------+----------+-------------+
| 1  | SIMPLE      | users |            | ALL  | users_email_unique |     |         |     | 1770 | 19       | Using where |
+----+-------------+-------+------------+------+--------------------+-----+---------+-----+------+----------+-------------+

[ SQL ran for 4.83 ms ] RAW SQL: insert into `ticket` (`user_id`, `expire_time`, `ticket`, `updated_at`, `created_at`) values (1, "2020-06-08 17:20:39", "08c14bace9bdfd9dbe3558adba463d1f198", "2020-06-01 17:20:39", "2020-06-01 17:20:39")

+----+-------------+--------+------------+------+---------------+-----+---------+-----+------+----------+-------+
| id | select_type | table  | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
+----+-------------+--------+------------+------+---------------+-----+---------+-----+------+----------+-------+
| 1  | INSERT      | ticket |            | ALL  |               |     |         |     |      |          |       |
+----+-------------+--------+------------+------+---------------+-----+---------+-----+------+----------+-------+

[ Response Load 88.63 ms] {"code":200,"data":{"user":{"id":1,"username":"koga","phone":"12345678910","email":"koga@gmail.com","created_at":"2020-06-01 14:45:09","updated_at":"2019-06-01 14:45:09","loginname":"koga","from":"api","regip":null,"regdate":null,"ticket":"08c14bace9bdfd9dbe3558adba463d1f198"}},"msg":"\u767b\u5f55\u6210\u529f\uff01"}