From 6eaf9e6f4630c77588a5329f20d698b0eb147185 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Tue, 18 Jan 2022 10:12:43 +0100 Subject: [PATCH] [Console] use STDOUT/ERR in ConsoleOutput to save opening too many file descriptors --- src/Symfony/Component/Console/Output/ConsoleOutput.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/Console/Output/ConsoleOutput.php b/src/Symfony/Component/Console/Output/ConsoleOutput.php index 966fca09942a3..484fcbdea24b9 100644 --- a/src/Symfony/Component/Console/Output/ConsoleOutput.php +++ b/src/Symfony/Component/Console/Output/ConsoleOutput.php @@ -153,7 +153,8 @@ private function openOutputStream() return fopen('php://output', 'w'); } - return @fopen('php://stdout', 'w') ?: fopen('php://output', 'w'); + // Use STDOUT when possible to prevent from opening too many file descriptors + return \defined('STDOUT') ? \STDOUT : (@fopen('php://stdout', 'w') ?: fopen('php://output', 'w')); } /** @@ -161,6 +162,11 @@ private function openOutputStream() */ private function openErrorStream() { - return fopen($this->hasStderrSupport() ? 'php://stderr' : 'php://output', 'w'); + if (!$this->hasStderrSupport()) { + return fopen('php://output', 'w'); + } + + // Use STDERR when possible to prevent from opening too many file descriptors + return \defined('STDERR') ? \STDERR : (@fopen('php://stderr', 'w') ?: fopen('php://output', 'w')); } }