问题描述:
[root@localhost www]# /usr/local/php/bin/php index.php
PHP Fatal error: Call to undefined function pcntl_fork() in /home/www/theard/threadProcessManager.php on line 69
解决办法:
1、从新编译php
./configure --enable-pcntl ``````````
2、不重新安装也可以,直接进你安装php时的源码目录ext/pcntl目录。
运行
phpize
[root@localhost pcntl]# ./configure --with-php-config=/usr/local/php/bin/php-config && make && make install
把生成的文件放到默认的目录里:
[root@localhost pcntl]# cp /usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/pcntl.so /usr/lib/php/modules/
然后在php.ini里加上这个extension
extension=pcntl.so
如果不加直接在你的程序里加载它(用dl()函数,该函数将被取消)也可以,特别对于 php 除了cmdline还要和apache做web工作的时候,因为web服务的时候加载pnctl模块爱出问题。
测试办法
test_fork.php:
echo "This is an echo before I called the fork command\n";
$pid = pcntl_fork();
if ($pid == -1) {
die("could not fork");
} else if ($pid) {
echo "I am the parent, pid = ". $pid ."\n";
} else {
echo "I am the child, pid = ". $pid ."\n";
}
echo "This is an echo after I called the fork command\n";
?>