我正在尝试派生一个命令行,使用pcntl_fork()运行XAMPP php进程。当我运行以下命令时:
$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);
}我得到了:
Fatal error: Call to undefined function pcntl_fork()有没有人能建议如何解决这个问题?
发布于 2013-12-09 22:13:42
当PHP用作Apache模块(如XAMPP)时,不能使用函数'pcntl_fork‘。您只能在CGI模式或命令行中使用pcntl_fork。
使用此函数将导致:'Fatal error: Call to undefined function: pcntl_fork()'
来源:http://php.net/manual/en/function.pcntl-fork.php
发布于 2013-11-11 23:51:11
要查看是否已安装,请运行:
php -i | grep pcntl
如果存在并启用了pcntl函数,则可能会禁用pcntl函数,这似乎是较新的PHP5.x安装中的默认设置。要进行检查,请运行:
php -i | grep disable_functions
如果看到pcntl_*函数列表,则需要编辑php.ini文件(在XAMPP内)并注释掉disable_functions=行
我建议你在OS上使用PHP的this distribution,它有最新的版本,我可以确认它确实有pcntl扩展。
发布于 2018-06-06 11:41:42
默认情况下,pcntl_*中的过程控制支持是不启用的。编译PHP时,您必须使用--enable-pcntl配置选项编译PHP的CGI或CLI版本(不要用作Apache模块),才能启用过程控制支持。
目前,此模块在非Unix平台 (Windows)上不起作用。
ref
https://stackoverflow.com/questions/16826530
复制相似问题