Pratik Bhujel has opened the Io\Terminal RFC for PHP 8.7. It would let PHP read single key presses and hidden password input on its own. It also handles raw mode and the terminal size, on both POSIX terminals and Windows consoles.

Why It Matters

If you've used an interactive prompt in a PHP CLI tool, it probably shelled out to stty to work. Symfony Console's question helper runs stty -icanon -echo, and Laravel Prompts runs stty -icanon -isig -echo. Both put the terminal in a mode where the code sees each key as you press it. Windows needs separate code for its Console API.

Nicolas Grekas from Symfony welcomed the RFC on the internals list:

PHP definitely needs native terminal support, calling stty is a workaround we've been carrying since way too long.

How It Works

Here is the example from the RFC:

use Io\Terminal\Key;
use Io\Terminal\SystemTerminal;
use Time\Duration;

$terminal = SystemTerminal::fromStdio();
$size = $terminal->getSize();

if ($size !== null) {
    printf("%dx%d\n", $size->cols, $size->rows);
}

$key = $terminal->readKey(Duration::fromSeconds(5));

if ($key === Key::Escape) {
    echo "Escape pressed\n";
}

SystemTerminal::fromStdio() connects to the process's standard input and output. You can also pass your own streams to fromStreams(). getSize() returns the columns and rows, or null when PHP can't get a real size. It doesn't fall back to the COLUMNS or LINES environment variables.

readKey() waits up to five seconds here. It returns a Key enum case for special keys like the arrows, Escape, or F1 through F12. Any other input comes back as a string, and a timeout returns null.

Two more methods handle text. readLine() reads a line, and readSecret() reads a password without echoing it to the screen.

How Raw Mode Works

A terminal normally buffers what you type until you press Enter. Raw mode turns that off, so your code gets each key press as it happens. Menus and search-as-you-type lists need this.

readKey() and readSecret() switch modes for you. For a longer interactive loop, enableRawMode() returns a token, and you hand it back when you're done:

$mode = $terminal->enableRawMode();

try {
    // interactive loop
} finally {
    $terminal->restoreMode($mode);
}

This part came out of review. Grekas suggested counting the active tokens per terminal, and Bhujel rewrote the implementation around it. Raw mode stays on while any token is alive. The original mode comes back when the last one is released, in any order.

The Testing Debate

Most of the thread since then has been about testing. Larry Garfield argued that "any IO boundary should be mockable," so Bhujel added interfaces. In version 0.3 of the RFC, Terminal and ModeToken are interfaces, and SystemTerminal is the native class.

Tim Düsterhus said the interfaces made the API "much worse." His view is that the terminal class isn't the IO boundary, the stream you pass into it is. You'd test by passing in a real pseudo-terminal opened with proc_open(). Bob Weinand agreed with him.

On October 5, Ilia Alshanetsky suggested dropping both interfaces and renaming SystemTerminal back to Terminal. Under his plan, readKey() would also accept plain streams like php://memory, so the same tests work on every OS. Bhujel has said he wants this settled before he changes the API again. Expect the class names in this article to change.

Where It Stands

Bhujel opened the internals discussion on September 27, 2026. The API has already changed a few times. Terminal::create() became SystemTerminal::fromStdio(), and TerminalSize gained a public constructor so tests can build one. The php-src implementation is under review.

The RFC is marked Under Discussion and has no vote scheduled. Of course, the RFC still needs to go through the usual voting process before it can become part of PHP. Existing PHP APIs stay unchanged, but code or extensions that declare the same Io\Terminal names will conflict.

You can follow its status on the RFC tracker, or read the full proposal and examples in the RFC on the PHP wiki.