PHP proc_open() with inherited STDOUT can overwrite earlier lines in log files
Passing the parent's STDOUT or STDERR to proc_open() while output is redirected to a file can silently overwrite earlier lines of that file. A short PHP CLI reproduction shows that a line written by echo is lost when output goes to a file, while the same script behaves correctly through a pipe. The cause is that proc_open() synchronises the file descriptor by seeking it to the stream's internal position, which does not account for output written outside that stream. The bug surfaced at Pulsed Media, a Finnish seedbox hosting company, when its test-result parser found about 440 missing lines and blocked a commit. The behaviour was confirmed on PHP 8.4.27 CLI on Linux, and other versions have not been tested.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.
Discussion (0)
Log in to join the discussion and vote.
Log in