pcntl_exec

(PHP 4 >= 4.2.0, PHP 5)

pcntl_exec --  Executes specified program in current process space

Description

void pcntl_exec ( string path [, array args [, array envs]] )

pcntl_exec() executes the program path with arguments args. path must be the path to a binary executable or a script with a valid path pointing to an executable in the shebang ( #!/usr/local/bin/perl for example) as the first line. See your system's man execve(2) page for additional information.

args is an array of argument strings passed to the program.

envs is an array of strings which are passed as environment to the program. The array is in the format of name => value, the key being the name of the environmental variable and the value being the value of that variable.

pcntl_exec() returns FALSE on error and does not return on success.


add a note add a note User Contributed Notes
michael dot ferre at mobileway dot com
20-Nov-2002 07:28
//To complete my last note
//If you use some object in your php code
//You will have some problem if you do a exit after include the
//child scripts
//You must use posix_kill() like that :

$CHILD_PID = pcntl_fork();
if($CHILD_PID == 0)
{   
  include ($script_path);
  posix_kill(getmypid(),9);
}

//This code is very simple it can be ameliorate ;)
michael dot ferre at mobileway dot com
19-Nov-2002 08:19
//If you are in php version between 4.1 and 4.2
//When you use pcntl_fork and after you want use
//pcntl_exec, you can because pcntl_exec isn't used before
//php 4.2 so let me show a solution :

$CHILD_PID = pcntl_fork();
if($CHILD_PID == 0)
{   
   include ($script_path);
   exit;
}

//$script_path is the  *.php page which you want lauch like
// a child .

//I don't know why php coder hadn't add  pcntl_exec in the
//same time that other function

//Michal F. php developer .