What are some best practices for securely passing parameters to the exec function in PHP?

When passing parameters to the exec function in PHP, it is important to sanitize and validate the input to prevent any potential security vulnerabilities such as command injection attacks. One way to securely pass parameters is to use escapeshellarg() function to escape and quote the parameter values before passing them to the exec function.

$param1 = "user_input_here";
$param2 = "another_user_input_here";

$param1 = escapeshellarg($param1);
$param2 = escapeshellarg($param2);

exec("command_here $param1 $param2");