From 8b5e26a12067730507b3ba4ca263750191707613 Mon Sep 17 00:00:00 2001 From: freek Date: Fri, 5 Jun 2015 00:37:35 +0200 Subject: [PATCH] add option to specify timeout of mysqldump --- CHANGELOG.md | 3 +++ README.md | 6 ++++++ .../Database/Databases/MySQLDatabase.php | 5 ++++- src/Console.php | 11 +++++++++-- src/config/laravel-backup.php | 6 ++++++ 5 files changed, 28 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c8165bb4..11c81116 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ All Notable changes to `laravel-backup` will be documented in this file +###2.5.0 +- Added option to specify the timeout of the mysqldump command + ###2.4.2 - Fixed an issue where the incorrect backup filename would be displayed diff --git a/README.md b/README.md index c6472602..82a9c441 100644 --- a/README.md +++ b/README.md @@ -123,6 +123,12 @@ return [ * See: https://dev.mysql.com/doc/refman/5.1/en/mysqldump.html#option_mysqldump_extended-insert */ 'useExtendedInsert' => false, + + /* + * If the dump of the db takes more seconds that the specified value, + * it will abort the backup. + */ + 'timeoutInSeconds' => 60, ], ]; ``` diff --git a/src/BackupHandlers/Database/Databases/MySQLDatabase.php b/src/BackupHandlers/Database/Databases/MySQLDatabase.php index 0a37c296..50f523a4 100644 --- a/src/BackupHandlers/Database/Databases/MySQLDatabase.php +++ b/src/BackupHandlers/Database/Databases/MySQLDatabase.php @@ -20,6 +20,7 @@ class MySQLDatabase implements DatabaseInterface * @param $password * @param $host * @param $port + * @param $socket */ public function __construct(Console $console, $database, $user, $password, $host, $port, $socket) { @@ -62,7 +63,9 @@ public function dump($destinationFile) escapeshellcmd($this->getSocketArgument()) ); - return $this->console->run($command); + + + return $this->console->run($command, config('laravel-backup.mysql.timeoutInSeconds')); } /** diff --git a/src/Console.php b/src/Console.php index 0edeb3c6..68676458 100644 --- a/src/Console.php +++ b/src/Console.php @@ -4,11 +4,18 @@ class Console { - public function run($command) + /** + * Run a command in the shell. + * + * @param $command + * @param $timeoutInSeconds + * @return bool|string + */ + public function run($command, $timeoutInSeconds = 60) { $process = new Process($command); - $process->setTimeout(60 * 1); + $process->setTimeout($timeoutInSeconds); $process->run(); diff --git a/src/config/laravel-backup.php b/src/config/laravel-backup.php index 308cb0bf..c32b6b32 100644 --- a/src/config/laravel-backup.php +++ b/src/config/laravel-backup.php @@ -80,5 +80,11 @@ * See: https://dev.mysql.com/doc/refman/5.1/en/mysqldump.html#option_mysqldump_extended-insert */ 'useExtendedInsert' => false, + + /* + * If the dump of the db takes more seconds that the specified value, + * it will abort the backup. + */ + 'timeoutInSeconds' => 60, ], ];