In the context of PHP web development, what are some alternative approaches to using the exec function for system command execution that may be more secure and reliable?

Using the exec function for system command execution in PHP can pose security risks due to potential command injection vulnerabilities. To mitigate these risks, consider using alternative approaches such as the use of functions like shell_exec, passthru, or proc_open, which provide more control over input sanitization and output handling.

// Using shell_exec as an alternative to exec for system command execution
$output = shell_exec('ls -la');
echo "<pre>$output</pre>";