PHPackages                             subhashladumor/laravel-optimizer - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. subhashladumor/laravel-optimizer

ActiveLibrary[Database &amp; ORM](/categories/database)

subhashladumor/laravel-optimizer
================================

All-in-one Laravel optimization suite for speed, caching, database, frontend, and cleanup

1.0.0(6mo ago)071MITPHPPHP ^8.0|^8.1|^8.2|^8.3

Since Oct 19Pushed 6mo agoCompare

[ Source](https://github.com/subhashladumor1/laravel-optimizer)[ Packagist](https://packagist.org/packages/subhashladumor/laravel-optimizer)[ RSS](/packages/subhashladumor-laravel-optimizer/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (7)Versions (3)Used By (0)

🚀 Laravel Optimizer
===================

[](#-laravel-optimizer)

[![Latest Version on Packagist](https://camo.githubusercontent.com/69c7c8f836753bcd4ae1e1c1b0033b918630bf87c0abf11b73c0becce19cab61/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f737562686173686c6164756d6f722f6c61726176656c2d6f7074696d697a65722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/subhashladumor/laravel-optimizer)[![Laravel Version](https://camo.githubusercontent.com/19d5bb0370853f3f5f64da8e47f7b2e14803b7fa5f7c8d04e347ac6849edb9ee/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c61726176656c2d31322e782d7265642e7376673f7374796c653d666c61742d737175617265)](https://laravel.com)[![PHP Version](https://camo.githubusercontent.com/86d78c3caab7ad314cfa93135c4a5ce37dd4e249659f65d00ef2f5c3aaadb6b3/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f737562686173686c6164756d6f722f6c61726176656c2d6d756c7469636c6f75642e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/subhashladumor/laravel-multicloud)[![License](https://camo.githubusercontent.com/a90b862a0dc343aaeea33b913981722b3ad8be15e04c5a159ca38c9d2eab874a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f737562686173686c6164756d6f722f6c61726176656c2d6f7074696d697a65722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/subhashladumor/laravel-optimizer)

**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.

---

✨ Features
----------

[](#-features)

### 🔧 Backend Optimization

[](#-backend-optimization)

- Optimize config, route, event, and view caching
- Auto-detect environment and suggest `.env` improvements
- Memory usage analyzer and recommendations

### 🗄️ Database Optimization

[](#️-database-optimization)

- Detect and log slow queries (configurable threshold)
- Suggest missing indexes based on query patterns
- Cache repeated query results intelligently
- Optimize database tables (MySQL)

### 💾 Cache Optimization

[](#-cache-optimization)

- Smart Redis/Memcached detection
- Auto-warm cache on deploy or config clear
- Cache TTL recommendations
- Cache hit rate analysis

### 🎨 Frontend Optimization

[](#-frontend-optimization)

- Auto-detect unminified CSS/JS files
- Image compression recommendations
- Add lazy loading suggestions for `` tags
- Gzip/Brotli compression detection

### 📬 Queue Optimization

[](#-queue-optimization)

- Tune retry counts, batch size, and memory limits
- Detect failed jobs and suggest retry strategies
- Queue configuration analysis

### 🧹 Cleanup &amp; Maintenance

[](#-cleanup--maintenance)

- Clear old logs, sessions, caches, temp files
- Configurable retention periods
- Safe cleanup with confirmation prompts

### 📊 Performance Analyzer

[](#-performance-analyzer)

- Comprehensive performance analysis
- TTFB, route speed, query count tracking
- Cache hit rate monitoring
- Performance score and grading system

---

📋 Requirements
--------------

[](#-requirements)

- PHP 8.0 or higher
- Laravel 9.x, 10.x, or 11.x

---

📦 Installation
--------------

[](#-installation)

Install the package via Composer:

```
composer require subhashladumor/laravel-optimizer
```

### Publish Configuration

[](#publish-configuration)

Publish the configuration file to customize settings:

```
php artisan vendor:publish --tag=optimizer-config
```

This will create `config/optimizer.php` in your application.

---

🎯 Usage
-------

[](#-usage)

### Available Commands

[](#available-commands)

CommandDescription`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 &amp; sessions`php artisan optimize:frontend`Optimize frontend assets`php artisan optimize:cleanup`Cleanup project logs &amp; temp files### Command Examples

[](#command-examples)

#### 1. Run All Optimizations

[](#1-run-all-optimizations)

```
php artisan optimize:all
```

**Output:**

```
🚀 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

```

#### 2. Analyze Application Performance

[](#2-analyze-application-performance)

```
php artisan optimize:analyze
```

Generate detailed report:

```
php artisan optimize:analyze --report
```

#### 3. Database Optimization

[](#3-database-optimization)

```
php artisan optimize:db
```

Show database statistics:

```
php artisan optimize:db --stats
```

#### 4. Cache Optimization

[](#4-cache-optimization)

```
php artisan optimize:cache
```

Analyze cache usage:

```
php artisan optimize:cache --analyze
```

#### 5. Frontend Optimization

[](#5-frontend-optimization)

```
php artisan optimize:frontend
```

Analyze frontend performance:

```
php artisan optimize:frontend --analyze
```

#### 6. Cleanup

[](#6-cleanup)

```
php artisan optimize:cleanup
```

Show cleanup statistics:

```
php artisan optimize:cleanup --stats
```

Force cleanup without confirmation:

```
php artisan optimize:cleanup --force
```

---

⚙️ Configuration
----------------

[](#️-configuration)

The `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,
    ],
];
```

---

🎭 Using the Facade
------------------

[](#-using-the-facade)

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();
```

---

🛠️ Helper Functions
-------------------

[](#️-helper-functions)

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();
```

---

📊 Performance Analysis
----------------------

[](#-performance-analysis)

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

### Performance Grading

[](#performance-grading)

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

---

🔄 Scheduled Optimization
------------------------

[](#-scheduled-optimization)

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');
}
```

---

🎯 Best Practices
----------------

[](#-best-practices)

### Production Environment

[](#production-environment)

1. **Always run optimizations** after deployment:

    ```
    php artisan optimize:all
    ```
2. **Disable debug mode**:

    ```
    APP_DEBUG=false
    ```
3. **Use Redis for caching and sessions**:

    ```
    CACHE_DRIVER=redis
    SESSION_DRIVER=redis
    ```
4. **Enable queue workers**:

    ```
    QUEUE_CONNECTION=redis
    ```

### Development Environment

[](#development-environment)

1. **Clear cache frequently** during development:

    ```
    php artisan optimize:cleanup --force
    ```
2. **Analyze performance** before going to production:

    ```
    php artisan optimize:analyze --report
    ```

---

🧪 Testing
---------

[](#-testing)

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-database
```

---

🤝 Contributing
--------------

[](#-contributing)

Contributions are welcome! Please feel free to submit a Pull Request.

---

📝 License
---------

[](#-license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

---

👨‍💻 Author
----------

[](#‍-author)

**Subhash Ladumor**

- Email:
- GitHub: [@subhashladumor](https://github.com/subhashladumor)

---

🙏 Acknowledgments
-----------------

[](#-acknowledgments)

- Inspired by Laravel's built-in optimization commands
- Built with ❤️ for the Laravel community

---

📚 Additional Resources
----------------------

[](#-additional-resources)

- [Laravel Documentation](https://laravel.com/docs)
- [Performance Optimization Guide](https://laravel.com/docs/deployment#optimization)
- [Database Query Optimization](https://laravel.com/docs/queries)

**Made with ❤️ by [Subhash Ladumor](https://github.com/subhashladumor)**

[⭐ Star this repo](https://github.com/subhashladumor/laravel-optimizer) | [🐛 Report Bug](https://github.com/subhashladumor/laravel-optimizer/issues) | [💡 Request Feature](https://github.com/subhashladumor/laravel-optimizer/issues)

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance66

Regular maintenance activity

Popularity5

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity51

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

204d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/f38ba994870f0b2c8855e3f4614b1a8ecfecda7114fa4a8d261b9c6bb192b20b?d=identicon)[subhashladumor1](/maintainers/subhashladumor1)

---

Top Contributors

[![subhashladumor1](https://avatars.githubusercontent.com/u/79623012?v=4)](https://github.com/subhashladumor1 "subhashladumor1 (6 commits)")

---

Tags

cleanuplaravellaravel-frameworklaravel-pacakgeslaravel-packageoptimizationlaraveldatabaseperformancecacheoptimizationfrontendspeedcleanup

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/subhashladumor-laravel-optimizer/health.svg)

```
[![Health](https://phpackages.com/badges/subhashladumor-laravel-optimizer/health.svg)](https://phpackages.com/packages/subhashladumor-laravel-optimizer)
```

###  Alternatives

[spatie/laravel-responsecache

Speed up a Laravel application by caching the entire response

2.8k8.2M51](/packages/spatie-laravel-responsecache)[mongodb/laravel-mongodb

A MongoDB based Eloquent model and Query builder for Laravel

7.1k7.2M71](/packages/mongodb-laravel-mongodb)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

255.2k](/packages/aedart-athenaeum)[ntanduy/cloudflare-d1-database

Easy configuration and setup for D1 Database connections in Laravel.

215.4k](/packages/ntanduy-cloudflare-d1-database)[sarfraznawaz2005/indexer

Laravel package to monitor SELECT queries and offer best possible INDEX fields.

562.7k](/packages/sarfraznawaz2005-indexer)[toponepercent/baum

Baum is an implementation of the Nested Set pattern for Eloquent models.

3154.7k](/packages/toponepercent-baum)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
