What are the differences between exec() and passthru() functions in PHP when executing commands?

The main difference between exec() and passthru() functions in PHP when executing commands lies in how they handle the output of the command. The exec() function only returns the last line of the command output, while passthru() displays the complete output directly to the browser. If you need to capture the full output of the command for further processing, passthru() is the better choice.

// Using passthru() to execute a command and display the full output
passthru('ls -l');