我已经阅读了http://us1.php.net/manual/en/function.pcntl-exec.php和http://php.net/manual/en/function.exec.php上的文档,但我无法真正知道它们之间的实际区别。
pcntl_exec()函数与标准的(类Unix风格)exec()函数完全相同。它与常规的PHP exec()函数不同之处在于,调用pcntl_exec()的进程将被调用的进程所替代。这是创建子进程的理想方法。
以下是一个简单示例(未进行错误检查):
switch (pcntl_fork()) {
case 0:
$cmd = "/path/to/command";
$args = array("arg1", "arg2");
pcntl_exec($cmd, $args);
// the child will only reach this point on exec failure,
// because execution shifts to the pcntl_exec()ed command
exit(0);
default:
break;
}
// parent continues
echo "I am the parent";
以下内容引自这里的评论: http://us1.php.net/manual/zh/function.pcntl-exec.php
exec
和pcntl_exec
的相对优缺点是什么。 - ironchicken