問題描述:
[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";
?>