phpr prints nothing until the script ends: everything written with echo,
fwrite(STDOUT), php://stdout or php://output is kept in memory and
written at exit, and flush() / fflush(STDOUT) don't change that. If the
process is killed, the output is lost. Writing to /dev/stdout or STDERR
comes out immediately.
This breaks interactive CLI programs (TUI games, prompts), progress output
and long-running scripts that stream logs.
Reproduce
<?php
echo "tick 1\n";
flush();
sleep(2);
echo "tick 2\n";
phpr flush.php | while IFS= read -r l; do echo "$l at +${SECONDS}s"; done
- PHP 8.5.7:
tick 1 appears immediately, tick 2 two seconds later.
- phpr: both lines appear together after two seconds.
The cause seems to be crates/php-cli/src/main.rs, which writes
outcome.rendered to stdout only after run_source_with_argv returns.
Found while running a terminal Snake game (plain PHP 8.4+) on phpr. The game
itself passes its PHPUnit suite and produces identical benchmark checksums on
phpr; only the interactive mode is affected. A local workaround (an output
buffer flushed to fopen('/dev/stdout')) makes it playable.
Environment: macOS 26.6.2 (Apple M1 Pro), Rust 1.96.0, commit 352d4129.
phprprints nothing until the script ends: everything written withecho,fwrite(STDOUT),php://stdoutorphp://outputis kept in memory andwritten at exit, and
flush()/fflush(STDOUT)don't change that. If theprocess is killed, the output is lost. Writing to
/dev/stdoutorSTDERRcomes out immediately.
This breaks interactive CLI programs (TUI games, prompts), progress output
and long-running scripts that stream logs.
Reproduce
tick 1appears immediately,tick 2two seconds later.The cause seems to be
crates/php-cli/src/main.rs, which writesoutcome.renderedto stdout only afterrun_source_with_argvreturns.Found while running a terminal Snake game (plain PHP 8.4+) on phpr. The game
itself passes its PHPUnit suite and produces identical benchmark checksums on
phpr; only the interactive mode is affected. A local workaround (an output
buffer flushed to
fopen('/dev/stdout')) makes it playable.Environment: macOS 26.6.2 (Apple M1 Pro), Rust 1.96.0, commit
352d4129.