From 4d222ce308cfdbe7c200b8f4203616737910724e Mon Sep 17 00:00:00 2001 From: Harlor Date: Fri, 25 Jul 2025 19:06:34 +0200 Subject: [PATCH 1/2] Fast path for non-interactive mode (e.g. piped SQL dump) --- src/Commands/sql/SqlCommands.php | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/Commands/sql/SqlCommands.php b/src/Commands/sql/SqlCommands.php index dc332bed8b..d828f3b7b3 100644 --- a/src/Commands/sql/SqlCommands.php +++ b/src/Commands/sql/SqlCommands.php @@ -137,13 +137,24 @@ public function drop($options = ['extra' => self::REQ]): void public function cli(InputInterface $input, $options = ['extra' => self::REQ]): void { $sql = SqlBase::create($options); - $process = $this->processManager()->shell($sql->connect(), null, $sql->getEnv()); + $sql_cmd = $sql->connect(); if (!Tty::isTtySupported()) { - $process->setInput($this->stdin()->getStream()); + // Fast path for non-interactive mode (e.g. piped SQL dump). + // Use direct passthru to avoid PHP I/O buffering. + $env = $sql->getEnv(); + $env_str = ''; + foreach ($env as $k => $v) { + $env_str .= "$k=" . escapeshellarg($v) . ' '; + } + + passthru($env_str . $sql_cmd); + exit(0); } else { + // Interactive mode (TTY): use ProcessManager for better control. + $process = $this->processManager()->shell($sql_cmd, null, $sql->getEnv()); $process->setTty((bool) $this->getConfig()->get('ssh.tty', $input->isInteractive())); + $process->mustRun($process->showRealtime()); } - $process->mustRun($process->showRealtime()); } /** From 69d0bf655329e3313c3ca137ce0ee5d1836b2558 Mon Sep 17 00:00:00 2001 From: Harlor Date: Fri, 25 Jul 2025 19:18:08 +0200 Subject: [PATCH 2/2] Avoid drush warning from exit(0); --- src/Commands/sql/SqlCommands.php | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/Commands/sql/SqlCommands.php b/src/Commands/sql/SqlCommands.php index d828f3b7b3..612459b011 100644 --- a/src/Commands/sql/SqlCommands.php +++ b/src/Commands/sql/SqlCommands.php @@ -141,20 +141,18 @@ public function cli(InputInterface $input, $options = ['extra' => self::REQ]): v if (!Tty::isTtySupported()) { // Fast path for non-interactive mode (e.g. piped SQL dump). // Use direct passthru to avoid PHP I/O buffering. - $env = $sql->getEnv(); $env_str = ''; - foreach ($env as $k => $v) { + foreach ($sql->getEnv() as $k => $v) { $env_str .= "$k=" . escapeshellarg($v) . ' '; } passthru($env_str . $sql_cmd); - exit(0); - } else { - // Interactive mode (TTY): use ProcessManager for better control. - $process = $this->processManager()->shell($sql_cmd, null, $sql->getEnv()); - $process->setTty((bool) $this->getConfig()->get('ssh.tty', $input->isInteractive())); - $process->mustRun($process->showRealtime()); + return; } + // Interactive mode (TTY): use ProcessManager for better control. + $process = $this->processManager()->shell($sql_cmd, null, $sql->getEnv()); + $process->setTty((bool) $this->getConfig()->get('ssh.tty', $input->isInteractive())); + $process->mustRun($process->showRealtime()); } /**