tsaikoga / performance-printer
PerformancePrinter is a laravel package to print each requests' performance infomation for development.
Requires
- php: ^8.0.0|^7.0.0
- laravel/framework: ^9.0|^8.0|^7.0|^6.0|^5.5
This package is auto-updated.
Last update: 2024-03-17 03:49:56 UTC
README
Performance Printer is a laravel package to print each requests' performance infomation for development.
require : Laravel/framework 5.5+
Features
- Request
Display request method, request path and request body.
- Files
The count of included files
- Query
Each raw SQL that be generated by request and the times it costs.
The explain of SQL
The SQL count of request
- Response
The response datas and the times it costs.
Usage
- Install the package for development environment:
Stable version:
composer require tsaikoga/performance-printer --dev
Unstable version:
composer require tsaikoga/performance-printer:dev-master --dev
You can add custom configuration for the printer.
- Create a file
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', ], ];
- In
.env
file, setlocal
to the application environment:
APP_ENV=local
- Run the server:
php artisan serve
If you are using nginx or apache as server.
Try to enable the logger for message in configuration instead, you can customize the log path (default path: /tmp/performance_printer.log
)
tail -f /tmp/performance_printer.log
Preview
Printing Result:
[ 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"}