2013-05-30 78 views
13

我試圖叉命令行運行使用pcntl_fork()的XAMPP php過程。當我運行以下命令:pcntl_fork()返回,致命錯誤:調用未定義的函數pcntl_fork()

$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() 

任何人都可以建議如何解決這一問題?

+0

什麼是你的操作系統?請注意,Windows沒有底層的'* fork()'系統調用。 –

+0

Macintosh - Lion –

+1

你成功安裝了'php5-pcntl'嗎? –

回答

7

要查看是否安裝,運行:

php -i | grep pcntl

如果它存在並啓用,則函數了pcntl有可能禁用,這似乎是較新的PHP 5.x中安裝的默認。要檢查,運行:

php -i | grep disable_functions

如果你看到的pcntl_ *功能列表,你需要編輯您的php.ini文件(XAMPP內),並註釋掉disable_functions=

我建議你使用PHP的this distribution OS X,它有最新版本,我可以確認是否有pcntl擴展名。

+0

評論「disabled_functions =」對我來說是不行的。 #ubuntu1404#php7.1 – Jacksonkr

23

當PHP用作Apache模塊(如XAMPP)時,不可能使用'pcntl_fork'函數。您只能在CGI模式或命令行中使用pcntl_fork。

使用此功能將導致: '致命錯誤:調用未定義功能:pcntl_fork()'

來源:http://php.net/manual/en/function.pcntl-fork.php

相關問題