PHP code example of zxch / indexlens
1. Go to this page and download the library: Download zxch/indexlens library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
zxch / indexlens example snippets
return [
'mode' => env('INDEXLENS_MODE', 'balanced'), // off|safe|balanced|investigate
'enabled' => true,
'slow_query_ms' => 100,
'detect_n_plus_one' => true,
'detect_missing_indexes' => true,
'run_explain' => true,
'store_profiles' => true,
'capture_cli' => env('INDEXLENS_CAPTURE_CLI', false),
'sample_rate' => (float) env('INDEXLENS_SAMPLE_RATE', 1.0),
'max_queries_per_request' => (int) env('INDEXLENS_MAX_QUERIES_PER_REQUEST', 250),
'persist_only_slow_requests' => env('INDEXLENS_PERSIST_ONLY_SLOW', false),
'memory_spike_kb' => 1024,
'n_plus_one_repeat_threshold' => 5,
'duplicate_query_threshold' => 3,
'regression_ignore_cli' => env('INDEXLENS_REGRESSION_IGNORE_CLI', true),
'regression_min_delta_ms' => (float) env('INDEXLENS_REGRESSION_MIN_DELTA_MS', 50),
'ci_budget' => [
'max_queries' => 50,
'max_sql_time' => 200,
],
];
use IndexLens\IndexLens\Facades\IndexLens;
IndexLens::enable();
IndexLens::scan();
IndexLens::routes();
IndexLens::recommendIndexes();
IndexLens::explainSlowQueries();
IndexLens::regressions();
IndexLens::report('json');
IndexLens::report('markdown');
IndexLens::report('html');
return view('indexlens::debug', [
'routes' => app('indexlens')->routes(),
]);
bash
composer vendor:publish --tag=indexlens-config
php artisan vendor:publish --tag=indexlens-migrations
php artisan migrate
bash
php artisan vendor:publish --tag=indexlens-views
bash
php artisan indexlens:scan
php artisan indexlens:routes
php artisan indexlens:regression
php artisan indexlens:ci --max-query=50 --max-time=200
php artisan indexlens:report --format=markdown --output=storage/app/indexlens-report.md
php artisan indexlens:report --format=html --output=storage/app/indexlens-report.html
php artisan indexlens:status
text
/dashboard -> 142 queries -> HIGH
/reports/export -> 600 queries -> CRITICAL
/users -> 12 queries -> GOOD
yaml
name: indexlens-performance
on:
pull_request:
push:
branches: [main]
jobs:
package-tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: shivammathur/setup-php@v2
with:
php-version: '8.3'
tools: composer
- run: composer install --no-interaction --prefer-dist
- run: php artisan test
text
src/
├── Console/
├── Facades/
├── Services/
├── Analyzers/
├── DTOs/
├── Models/
├── Repositories/
├── Commands/
├── Contracts/
└── IndexLensServiceProvider.php