pcntl_fork() returning, Fatal error: Call to undef

2019-06-14 23:17发布

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?

3条回答
Rolldiameter
2楼-- · 2019-06-14 23:33

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.

查看更多
小情绪 Triste *
3楼-- · 2019-06-14 23:39

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

查看更多
叼着烟拽天下
4楼-- · 2019-06-14 23:52

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

查看更多
登录 后发表回答