Program Execution

9 entries

escapeshellarg Function Escapes a string into a safe single shell argument (against command injection). exec Function Executes an external command and captures its output (via the shell, returning the last line). passthru / escapeshellcmd Function passthru streams the child output straight through (no return string, fit for binary data); escapeshellcmd escapes metacharacters in a command string in place, complementing escapeshellarg's "wrap the whole value in quotes" - escaping functions exist precisely because PHP goes through the shell by default. popen / pclose Function One-way process pipes: popen opens a unidirectional pipe to a child process ("r" reads its stdout, "w" writes to its stdin) whose pointer works with fgets/fwrite; pclose closes the pipe, reaps the child and returns its termination status — the direct descendant of Unix popen(3), complementing proc_open's two-way pipes. pcntl_fork Function Unix process forking (PCNTL extension, unavailable on Windows builds): the return value is the identity — the parent gets the child PID, the child gets 0; pair every fork with a waitpid reap to avoid zombies. proc_get_status / proc_close / proc_terminate Function The proc_open trio: proc_get_status polls the child's state (running/exitcode/stopped), proc_close blocks to reap and yields the exit code, proc_terminate sends a kill signal - stopping and reaping are two steps, kill first then reap. proc_open Function Spawns a child process with bidirectional pipes: descriptor_spec maps fd 0/1/2, $pipes receives PHP-side handles, proc_close reaps - the only exec-family function with two-way I/O. shell_exec Function Executes a command via the shell and returns the full output as a string (equivalent to the backtick syntax). system Function Executes an external command and streams its output straight to this process's stdout (returning the last line).