将stdout和stderr重定向到同一个管道中

I would like to invoke a child process in PHP, in non-blocking manner, and point both stdout and stderr into the same pipe, so that lines on both stdout and stderr appear together in their order of generation, as if executed on a console.

Pointing both at a temp file would be highly undesirable.

The process is single-threaded, so no simultaneous calls to write() expected. Naturally, I'd like to capture the process' output.

All the functions to start a process in PHP except of pcntl_fork() and pcntl_exec() will start the command in a shell. Use IO redirection:

echo shell_exec('command 2>&1');

The expression 2>&1 redirects the file descriptor 2 (stderr) into file descriptor 1 (stdout).