alicfeng / laravel-runtime
Laravel 运行时库
v1.0
2019-03-21 15:11 UTC
Requires (Dev)
- phpunit/phpunit: @stable
This package is auto-updated.
Last update: 2024-09-13 05:19:36 UTC
README
Laravel 运行时
Laravel 应用程序的laravel-runtime功能
前言
laravel-runtime
是一个Laravel
插件项目
无论在开发、测试还是生产环境中,我们都很注重请求的数据。一般做法是将有价值的数据写入日志中,以便于调试和问题排查。在Request
到达控制器之前,我们使用Http
中间件拦截并处理数据信息的写入,即在中间件中做日志记录。
同时,在开发和测试时,一个合格的开发者总会关注接口是否存在性能问题,比如接口请求的时间消耗等。此插件可以通过CLI
模式在终端以表格形式展示接口的基本状况,Web端界面也可以简约展示,如下所示:
CLI终端
WEB端
功能
- 接口请求的核心数据日志记录
- 接口请求记录分析
环境要求
PHP
>=7.0composer
laravel
安装
composer require "alicfeng/laravel-runtime"
配置
-
在
config/app.php
配置中添加AlicFeng\Runtime\ServiceProvider\RuntimeServiceProvider::class
-
在
app/Http/Kernel.php
中添加中间件\AlicFeng\Runtime\Middleware\RuntimeMiddleware::class
-
生成配置文件
php artisan vendor:publish --provider="AlicFeng\Runtime\ServiceProvider\RuntimeServiceProvider"
使用
CLI
#使用帮助 ➜ php artisan samego:runtime help usage: php artisan samego:runtime [help] [--service {reload|analysis}] [--start] [--end] # 查看接口请求情况分析(支持时间段) ➜ php artisan samego:runtime --service=analysis ➜ php artisan samego:runtime --service=analysis --start={opition|strtotime|0} ➜ php artisan samego:runtime --service=analysis --end={opition|strtotime|time()} # 分析数据重载 ➜ php artisan samego:runtime --service=reload
WEB
在浏览器中打开$host/runtime/analysis
即可看到展示~
tail日志
➜ tail -f storage/logs/laravel-2019-04-24.log [2019-04-24 11:38:44] production.INFO: trace request message begin [2019-04-24 11:38:44] production.INFO: router : order/v1/interface/name [2019-04-24 11:38:44] production.INFO: method : POST [2019-04-24 11:38:44] production.INFO: ip : 113.118.235.220 [2019-04-24 11:38:44] production.INFO: params : {"header":{"userToken":"token"},"body":{"param":"alicfeng"} [2019-04-24 11:38:44] production.INFO: trace request message end