要在不等待输出的情况下调用shell_exec(),可以使用以下方法:
$output = shell_exec("command > /dev/null 2>&1");
$descriptorspec = array(
0 => array("pipe", "r"), // stdin
1 => array("pipe", "w"), // stdout
2 => array("pipe", "w") // stderr
);
$process = proc_open("command", $descriptorspec, $pipes);
if (is_resource($process)) {
fclose($pipes[0]); // 关闭stdin
fclose($pipes[1]); // 关闭stdout
fclose($pipes[2]); // 关闭stderr
proc_close($process);
}
请注意,这些方法将输出完全丢弃,不会返回给调用者。如果您需要对输出进行处理或记录,请使用适当的方法来保存输出。