简体   繁体   English

php中pcntl_exec和exec有什么区别?

[英]what is the difference between pcntl_exec and exec in php?

我已经阅读了http://us1.php.net/manual/en/function.pcntl-exec.phphttp://php.net/manual/en/function.exec.php上的文档,但我可以不能真正说出实际的区别是什么。

The pcntl_exec() function works exactly like the standard (unix-style) exec() function. pcntl_exec()函数的工作原理与标准(unix样式)exec()函数完全相同。 It differs from the regular PHP exec() function in that the process calling the pcntl_exec() is replaced with the process that gets called. 它与常规PHP exec()函数的不同之处在于,调用pcntl_exec()的进程被替换为被调用的进程。 This is the ideal method for creating children 这是创建孩子的理想方法

. In a simple example (that does no error checking): 在一个简单的示例中(不进行错误检查):

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";

Referred from comments here: http://us1.php.net/manual/en/function.pcntl-exec.php 从此处的评论引用: http : //us1.php.net/manual/en/function.pcntl-exec.php

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM