What are the differences between using exec() and shell_exec() functions in PHP for executing external commands, and when is each method more appropriate?

When executing external commands in PHP, the `exec()` function is typically used when you need to capture the output of the command, while `shell_exec()` is used when you simply want to execute the command and don't need its output. `exec()` returns the last line of the command output, while `shell_exec()` returns the full output as a string.

// Using exec() to capture the output of an external command
$output = exec('ls -l');
echo $output;

// Using shell_exec() to execute an external command without capturing the output
shell_exec('mkdir new_directory');