subhashladumor/laravel-optimizer 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

subhashladumor/laravel-optimizer

Composer 安装命令:

composer require subhashladumor/laravel-optimizer

包简介

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

README 文档

README

Latest Version on Packagist Laravel Version PHP Version License

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

🔧 Backend Optimization

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

🗄️ 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

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

🎨 Frontend Optimization

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

📬 Queue Optimization

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

🧹 Cleanup & Maintenance

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

📊 Performance Analyzer

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

📋 Requirements

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

📦 Installation

Install the package via Composer:

composer require subhashladumor/laravel-optimizer

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

Available Commands

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

Command Examples

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

php artisan optimize:analyze

Generate detailed report:

php artisan optimize:analyze --report

3. Database Optimization

php artisan optimize:db

Show database statistics:

php artisan optimize:db --stats

4. Cache Optimization

php artisan optimize:cache

Analyze cache usage:

php artisan optimize:cache --analyze

5. Frontend Optimization

php artisan optimize:frontend

Analyze frontend performance:

php artisan optimize:frontend --analyze

6. Cleanup

php artisan optimize:cleanup

Show cleanup statistics:

php artisan optimize:cleanup --stats

Force cleanup without confirmation:

php artisan optimize:cleanup --force

⚙️ 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

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

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

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

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

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

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

  1. Clear cache frequently during development:

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

    php artisan optimize:analyze --report

🧪 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

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

📝 License

The MIT License (MIT). Please see License File for more information.

👨‍💻 Author

Subhash Ladumor

🙏 Acknowledgments

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

📚 Additional Resources

Made with ❤️ by Subhash Ladumor

⭐ Star this repo | 🐛 Report Bug | 💡 Request Feature

subhashladumor/laravel-optimizer 适用场景与选型建议

subhashladumor/laravel-optimizer 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 8 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 10 月 19 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「database」 「performance」 「cache」 「optimization」 「laravel」 「speed」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 subhashladumor/laravel-optimizer 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 subhashladumor/laravel-optimizer 我们能提供哪些服务?
定制开发 / 二次开发

基于 subhashladumor/laravel-optimizer 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 8
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 25
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-10-19