Created
June 11, 2018 13:08
-
-
Save sasin91/04d1d0d3c670df646ccc146baab44cd3 to your computer and use it in GitHub Desktop.
Defragment your MySQL database
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Console\Commands; | |
use Illuminate\Console\Command; | |
use Symfony\Component\Process\Process; | |
use Symfony\Component\Process\Exception\ProcessFailedException; | |
class DatabaseOptimizeCommand extends Command | |
{ | |
/** | |
* The name and signature of the console command. | |
* | |
* @var string | |
*/ | |
protected $signature = 'db:optimize'; | |
/** | |
* The console command description. | |
* | |
* @var string | |
*/ | |
protected $description = 'Make sure the database is healthy.'; | |
/** | |
* Execute the console command. | |
* | |
* @return mixed | |
*/ | |
public function handle() | |
{ | |
$connection = config('database.connections.'.config('database.default')); | |
$process = new Process("mysqlcheck -h {$connection['host']} -o {$connection['database']} -u{$connection['username']} -p{$connection['password']}"); | |
$process->run(); | |
throw_unless($process->isSuccessful(), ProcessFailedException::class, $process); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment