PHP code example of gigerit / laravel-mysql-optimizer

1. Go to this page and download the library: Download gigerit/laravel-mysql-optimizer 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/ */

    

gigerit / laravel-mysql-optimizer example snippets




return [
    'database' => env('DB_DATABASE'),
];

use MySQLOptimizer\Jobs\OptimizeTablesJob;

// Queue optimization for specific tables (logging enabled by default)
OptimizeTablesJob::dispatch('my_database', ['users', 'posts']);

// Send to a specific queue
OptimizeTablesJob::dispatch('my_database', ['users', 'posts'])
    ->onQueue('database-optimization');

// Delay execution
OptimizeTablesJob::dispatch('my_database', ['users', 'posts'])
    ->delay(now()->addMinutes(5));

// Disable logging explicitly
OptimizeTablesJob::dispatch('my_database', ['users', 'posts'], false);

use Illuminate\Console\Scheduling\Schedule;
use MySQLOptimizer\Jobs\OptimizeTablesJob;

protected function schedule(Schedule $schedule)
{
    $schedule->job(new OptimizeTablesJob())
        ->weekly()
        ->sundays()
        ->at('02:00');
}

use Illuminate\Console\Scheduling\Schedule;
use MySQLOptimizer\Jobs\OptimizeTablesJob;

protected function schedule(Schedule $schedule)
{
    $schedule->job(new OptimizeTablesJob(
        config('database.default'),
        ['users', 'orders', 'products']
    ))->daily()->at('03:00');
}

protected function schedule(Schedule $schedule)
{
    $schedule->command('db:optimize')
        ->weekly()
        ->sundays()
        ->at('02:00');
}
bash
php artisan vendor:publish --provider="MySQLOptimizer\ServiceProvider"
bash
php artisan db:optimize [--database=default] [--table=*] [--queued] [--no-log]
bash
php artisan db:optimize
bash
php artisan db:optimize --table=users --table=posts
bash
php artisan db:optimize --database=my_database
bash
php artisan db:optimize --queued
bash
php artisan queue:work