Query Analyzer for Laravel
, (*1)
Quickstart
composer require rokde/laravel-query-analyzer
Add to providers in config/app.php:, (*2)
Rokde\LaravelQueryAnalyzer\LaravelQueryAnalyzerProvider::class,
Installation
Add to your composer.json following lines, (*3)
"require": {
"rokde/laravel-query-analyzer": "~0.0"
}
Add Rokde\LaravelQueryAnalyzer\LaravelQueryAnalyzerProvider::class, to providers in config/app.php., (*4)
Run php artisan vendor:publish --provider="Rokde\LaravelQueryAnalyzer\LaravelQueryAnalyzerProvider", (*5)
Configuration
enabled
Is the analyzing enabled or not., (*6)
Usage
You have a console command to get all queries listed., (*7)
List all queries
$> php artisan analyze:queries
Lists all queries. You have --limit and --offset as options for paginate through all the queries., (*8)
Example output:, (*9)
01 select * from `users` where `users`.`id` = ? limit 1
02 select * from `profiles` where `profiles`.`user_id` = ? and `profiles`.`user_id` is not null
List details of one query
$> php artisan analyze:queries 1
Lists details for query number 1., (*10)
Example output:, (*11)
select * from `users` where `users`.`id` = ? limit 1
+-------+---------+---------+------+------+
| count | fastest | slowest | avg | mode |
+-------+---------+---------+------+------+
| 14 | 0.4 | 0.73 | 0.53 | 0.58 |
+-------+---------+---------+------+------+
+----------+---------+---------+------+------+
| bindings | fastest | slowest | avg | mode |
+----------+---------+---------+------+------+
| [1] | 0.4 | 0.73 | 0.53 | 0.58 |
| [2] | 0.41 | 0.74 | 0.54 | 0.59 |
+----------+---------+---------+------+------+
You can see the summary of all queries combined and afterwards the bindings-dependent timings. Maybe some bindings
cause an extra long run., (*12)
Clear the data
$> php artisan analyze:clear
Clears the whole data for analysis., (*13)