When one program runs another program, the execution of
the second program is actually a two-step procedure. First, the calling process
forks and makes a duplicate of itself, and then immediately does an exec call
to replace the executable code and memory with that of the new program.
If you just want to run a program and read the output or write to it, there are
easier ways of doing it, such as popen(). But, if you must be able to both read
and write to the program, you need to manually fork and exec from PHP, or
use the proc_open() function. (more…)
