From c003fb9585ae239e4f3371a81fd489bddb801c6c Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Tue, 20 Feb 2024 14:48:52 +0100 Subject: [PATCH] Faster dump by less tiny writes() --- src/Mysqldump.php | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/Mysqldump.php b/src/Mysqldump.php index 89f5bb6..a6e3cf3 100644 --- a/src/Mysqldump.php +++ b/src/Mysqldump.php @@ -837,6 +837,7 @@ private function listValues(string $tableName) $ignore = $this->settings->isEnabled('insert-ignore') ? ' IGNORE' : ''; $count = 0; + $line = ''; foreach ($resultSet as $row) { $count++; $values = $this->prepareColumnValues($tableName, $row); @@ -844,34 +845,33 @@ private function listValues(string $tableName) if ($onlyOnce || !$this->settings->isEnabled('extended-insert')) { if ($this->settings->isEnabled('complete-insert') && count($colNames)) { - $lineSize += $this->write(sprintf( + $line .= sprintf( 'INSERT%s INTO `%s` (%s) VALUES (%s)', $ignore, $tableName, implode(', ', $colNames), $valueList - )); - } else { - $lineSize += $this->write( - sprintf('INSERT%s INTO `%s` VALUES (%s)', $ignore, $tableName, $valueList) ); + } else { + $line .= sprintf('INSERT%s INTO `%s` VALUES (%s)', $ignore, $tableName, $valueList); } $onlyOnce = false; } else { - $lineSize += $this->write(sprintf(',(%s)', $valueList)); + $line .= sprintf(',(%s)', $valueList); } - if (($lineSize > $this->settings->getNetBufferLength()) + if ((strlen($line) > $this->settings->getNetBufferLength()) || !$this->settings->isEnabled('extended-insert')) { $onlyOnce = true; - $lineSize = $this->write(';' . PHP_EOL); + $this->write($line . ';' . PHP_EOL); + $line = ''; } } $resultSet->closeCursor(); - if (!$onlyOnce) { - $this->write(';' . PHP_EOL); + if ($line !== '') { + $this->write($line. ';' . PHP_EOL); } $this->endListValues($tableName, $count);