Bypassing Intermediate Shell Process with proc_open() in PHP
Back to Blog

Bypassing Intermediate Shell Process with proc_open() in PHP

In PHP, if you want to run another process with the function proc_open(), e.g. proc_open("php script.php", $d, $p), it actually creates two processes:

the first one is an intermediate shell process that calls the target process the second one is the actual target process (i.e. php)

proc_open() returns a handle to the PID of the first process only.

If we want to remove this intermediate process, we can call proc_open(["php", "script.php"], $d, $p) instead (by supplying an array instead of a command string). By doing this, proc_open() calls the target process directly and returns a handle to that PID.