pcntl_fork() returning, Fatal error: Call to undefined function pcntl_fork()

Ben Pearce picture Ben Pearce · May 30, 2013 · Viewed 28.4k times · Source

I'm trying to fork a command line run XAMPP php process using pcntl_fork(). When I run the command below:

$pid = pcntl_fork();
if($pid == -1){
    file_put_contents('testlog.log',"\r\nFork Test",FILE_APPEND);
    return 1; //error
}
else if($pid){
    return 0; //success
}
else{   
    file_put_contents($log, 'Running...', FILE_APPEND);
}

I get:

Fatal error: Call to undefined function pcntl_fork()

Can anyone suggest how to fix this?

Answer

Andrea picture Andrea · Dec 9, 2013

It is not possible to use the function 'pcntl_fork' when PHP is used as Apache module (such as XAMPP). You can only use pcntl_fork in CGI mode or from command-line.

Using this function will result in: 'Fatal error: Call to undefined function: pcntl_fork()'

Source: http://php.net/manual/en/function.pcntl-fork.php