The php Function Proc_Open
If you are working on a PHP web application that interacts with external programs, you may need to pass large amounts of data to those programs in order to read the output or send commands. This is where the php function proc_open comes in. This function allows you to directly start a program, and then pipe the standard input and output to it.
Proc_open is a useful function that should be used in conjunction with the function proc_close to ensure you clean up after you are done interacting with the external process. The indexed array contains the descriptor numbers 0 (stdin), 1 (stdout) and 2 (stderr). These are the same handles that you can use in your script, so it is important to close them when you are finished with your task.
If bypass_shell is set to true, the file descriptor numbers passed to the child process are not limited to 0 and 1. You can pass any valid file descriptor number to the process, which is very useful for passing passphrases to programs like PGP and GPG in a more secure manner. This also allows you to read status information provided by those programs on auxiliary file descriptors instead of the main ones, which can be a great benefit on systems that do not have support for inotify.
Note that if you are using a windows server, it is very important to make sure that any user supplied input passed to the proc_open function is escaped with escapeshellarg() or escapeshellcmd()to prevent users from tricking the system into running arbitrary commands. You should also ensure that any output from the program that is redirected to stdout or another input stream is also redirected, otherwise you may end up with a deadlock situation.