Repository: symfony/symfony
File: src/Symfony/Component/Console/Helper/QuestionHelper.php (PHP)

Code before:
            return false;
        }

        if (isset(self::$stdinIsInteractive)) {
            return self::$stdinIsInteractive;
        }

        return self::$stdinIsInteractive = @stream_isatty(fopen('php://stdin', 'r'));
    }

    /**
     * Reads one or more lines of input and returns what is read.
     *
     * @param resource $inputStream The handler resource
     * @param Question $question    The question being asked
     */
    private function readInput($inputStream, Question $question): string|false
    {
        if (null !== $question->getTimeout() && $this->isInteractiveInput($inputStream)) {
            $read = [$inputStream];
            $write = null;
            $except = null;
            $timeoutSeconds = $question->getTimeout();
            $changedStreams = stream_select($read, $write, $except, $timeoutSeconds);

            if (0 === $changedStreams) {
                throw new MissingInputException(\sprintf('Timed out after waiting for input for %d second%s.', $timeoutSeconds, 1 === $timeoutSeconds ? '' : 's'));
            }
        }

        if (!$question->isMultiline()) {
            $cp = $this->setIOCodepage();
            $ret = fgets($inputStream, 4096);

            return $this->resetIOCodepage($cp, $ret);
        }

        $multiLineStreamReader = $this->cloneInputStream($inputStream);
        if (null === $multiLineStreamReader) {
            return false;
        }

        $ret = '';
        $cp = $this->setIOCodepage();
        while (false !== ($char = fgetc($multiLineStreamReader))) {
            if (\PHP_EOL === "{$ret}{$char}") {
                break;
            }
            $ret .= $char;
        }


Review comment (suggestion):
```suggestion
            if (0 === stream_select([$inputStream], null, null, $question->getTimeout())) {
```

Code after:
            return false;
        }

        if (isset(self::$stdinIsInteractive)) {
            return self::$stdinIsInteractive;
        }

        return self::$stdinIsInteractive = @stream_isatty(fopen('php://stdin', 'r'));
    }

    /**
     * Reads one or more lines of input and returns what is read.
     *
     * @param resource $inputStream The handler resource
     * @param Question $question    The question being asked
     */
    private function readInput($inputStream, Question $question): string|false
    {
        if (null !== $question->getTimeout() && $this->isInteractiveInput($inputStream)) {
            $read = [$inputStream];
            $write = null;
            $except = null;
            $timeoutSeconds = $question->getTimeout();
            $changedStreams = stream_select($read, $write, $except, $timeoutSeconds);

            if (0 === $changedStreams) {
                throw new MissingInputException(\sprintf('Timed out after waiting for input for %d second%s.', $timeoutSeconds, 1 === $timeoutSeconds ? '' : 's'));
            }
        }

        if (!$question->isMultiline()) {
            $cp = $this->setIOCodepage();
            $ret = fgets($inputStream, 4096);

            return $this->resetIOCodepage($cp, $ret);
        }

        $multiLineStreamReader = $this->cloneInputStream($inputStream);
        if (null === $multiLineStreamReader) {
            return false;
        }

        $ret = '';
        $cp = $this->setIOCodepage();
        while (false !== ($char = fgetc($multiLineStreamReader))) {
            if ("\x4" === $char || \PHP_EOL === "{$ret}{$char}") {
                break;
            }
            $ret .= $char;
        }