问题
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?
回答1:
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
回答2:
To see if it is installed, run:
php -i | grep pcntl
If it is present and enabled then the pcntl function are likely disabled, which appears to be the default in newer PHP 5.x installs. To check, run:
php -i | grep disable_functions
If you see a list of pcntl_* functions, you'll need to edit your php.ini file (inside of XAMPP) and comment out the line disable_functions=
I'd recommend you use this distribution of PHP for OS X, which has current versions and I can confirm does have the pcntl
extension.
回答3:
pcntl_*
functions, Process Control support in PHP is not enabled by default. You have to compile the CGI or CLI version (don't used as Apache module) of PHP with --enable-pcntl
configuration option when compiling PHP to enable Process Control support.
Currently, this module will not function on non-Unix platforms (Windows).
ref
来源:https://stackoverflow.com/questions/16826530/pcntl-fork-returning-fatal-error-call-to-undefined-function-pcntl-fork