All-in-one Laravel optimization suite for speed, caching, database, frontend, and cleanup.
Laravel Optimizer Pro is a comprehensive performance optimization package that improves your Laravel application across multiple dimensions: backend caching, database queries, frontend assets, queue management, and automated cleanup.
- Optimize config, route, event, and view caching
- Auto-detect environment and suggest
.envimprovements - Memory usage analyzer and recommendations
- Detect and log slow queries (configurable threshold)
- Suggest missing indexes based on query patterns
- Cache repeated query results intelligently
- Optimize database tables (MySQL)
- Smart Redis/Memcached detection
- Auto-warm cache on deploy or config clear
- Cache TTL recommendations
- Cache hit rate analysis
- Auto-detect unminified CSS/JS files
- Image compression recommendations
- Add lazy loading suggestions for
<img>tags - Gzip/Brotli compression detection
- Tune retry counts, batch size, and memory limits
- Detect failed jobs and suggest retry strategies
- Queue configuration analysis
- Clear old logs, sessions, caches, temp files
- Configurable retention periods
- Safe cleanup with confirmation prompts
- Comprehensive performance analysis
- TTFB, route speed, query count tracking
- Cache hit rate monitoring
- Performance score and grading system
- PHP 8.0 or higher
- Laravel 9.x, 10.x, or 11.x
Install the package via Composer:
composer require subhashladumor/laravel-optimizerPublish the configuration file to customize settings:
php artisan vendor:publish --tag=optimizer-configThis will create config/optimizer.php in your application.
| Command | Description |
|---|---|
php artisan optimize:all |
Run all optimizations |
php artisan optimize:analyze |
Analyze performance |
php artisan optimize:db |
Optimize and analyze database |
php artisan optimize:cache |
Optimize cache & sessions |
php artisan optimize:frontend |
Optimize frontend assets |
php artisan optimize:cleanup |
Cleanup project logs & temp files |
php artisan optimize:allOutput:
π Starting Laravel Optimizer Pro...
βοΈ Optimizing Backend...
β Backend optimization completed successfully
ποΈ Optimizing Database...
β Database optimization completed successfully
πΎ Optimizing Cache...
β Cache optimization completed successfully
π¨ Optimizing Frontend...
β Frontend optimization completed successfully
π¬ Optimizing Queue...
β Queue optimization completed successfully
π§Ή Cleaning up...
β Cleanup optimization completed successfully
β
All optimizations completed in 2.45s
php artisan optimize:analyzeGenerate detailed report:
php artisan optimize:analyze --reportphp artisan optimize:dbShow database statistics:
php artisan optimize:db --statsphp artisan optimize:cacheAnalyze cache usage:
php artisan optimize:cache --analyzephp artisan optimize:frontendAnalyze frontend performance:
php artisan optimize:frontend --analyzephp artisan optimize:cleanupShow cleanup statistics:
php artisan optimize:cleanup --statsForce cleanup without confirmation:
php artisan optimize:cleanup --forceThe config/optimizer.php file contains all configuration options:
return [
// Slow query threshold (in milliseconds)
'slow_query_threshold' => 200,
// Preferred cache driver
'cache_driver' => 'redis',
// Cache TTL settings
'cache_ttl' => [
'config' => 3600,
'routes' => 3600,
'views' => 3600,
'queries' => 600,
],
// Cleanup settings
'cleanup' => [
'log_days' => 7,
'session_days' => 30,
'optimize_schedule' => 'weekly',
],
// Frontend optimization
'frontend' => [
'minify' => true,
'image_compression' => true,
'lazyload' => true,
'compression' => 'gzip',
],
// Database optimization
'database' => [
'analyze_indexes' => true,
'cache_queries' => true,
'log_slow_queries' => true,
],
// Queue optimization
'queue' => [
'retry_limit' => 3,
'batch_size' => 100,
'memory_limit' => '512M',
'timeout' => 60,
],
];You can use the OptimizerPro facade to access analyzer functionality:
use SubhashLadumor\LaravelOptimizer\Facades\OptimizerPro;
// Analyze performance
$analysis = OptimizerPro::analyze();
// Generate detailed report
$report = OptimizerPro::generateReport();The package includes several helper functions:
// Format bytes
optimizer_format_bytes(1024); // "1 KB"
// Get memory usage
optimizer_memory_usage(); // "128 MB"
// Get peak memory
optimizer_peak_memory(); // "256 MB"
// Get execution time
optimizer_execution_time(); // 150.25 (ms)
// Cache with recommended TTL
optimizer_cache_remember('key', 'config', function() {
return expensive_operation();
});
// Log optimization activity
optimizer_log('Custom optimization completed', ['key' => 'value']);
// Check if production
optimizer_is_production(); // true/false
// Should cache?
optimizer_should_cache(); // true/false
// Get config value
optimizer_get_config('slow_query_threshold', 200);
// Clear all cache
optimizer_clear_all_cache();
// Warm cache
optimizer_warm_cache();The analyzer provides comprehensive performance metrics:
- Performance Metrics: Request time, memory usage, peak memory
- Route Analysis: Total routes, middleware usage
- Database Analysis: Connection time, query count, slow queries
- Cache Analysis: Driver type, read/write performance, hit rate
- System Information: PHP version, Laravel version, environment
The analyzer assigns a performance score (0-100) and grade (A-F):
- A (90-100): Excellent performance
- B (80-89): Good performance
- C (70-79): Average performance
- D (60-69): Below average
- F (0-59): Poor performance
Add to your app/Console/Kernel.php:
protected function schedule(Schedule $schedule)
{
// Run cleanup weekly
$schedule->command('optimize:cleanup --force')
->weekly()
->sundays()
->at('01:00');
// Analyze performance daily
$schedule->command('optimize:analyze')
->daily()
->at('02:00');
}-
Always run optimizations after deployment:
php artisan optimize:all
-
Disable debug mode:
APP_DEBUG=false
-
Use Redis for caching and sessions:
CACHE_DRIVER=redis SESSION_DRIVER=redis
-
Enable queue workers:
QUEUE_CONNECTION=redis
-
Clear cache frequently during development:
php artisan optimize:cleanup --force
-
Analyze performance before going to production:
php artisan optimize:analyze --report
The package is designed to be safe and non-destructive. Always test in a staging environment first:
# Test analysis (read-only)
php artisan optimize:analyze
# Test with skip options
php artisan optimize:all --skip-cleanup --skip-databaseContributions are welcome! Please feel free to submit a Pull Request.
The MIT License (MIT). Please see License File for more information.
Subhash Ladumor
- Email: subhash@example.com
- GitHub: @subhashladumor
- Inspired by Laravel's built-in optimization commands
- Built with β€οΈ for the Laravel community
Made with β€οΈ by Subhash Ladumor