Friday, 4 December 2015

Install and enable "pcntl_fork" php module in ubuntu 14.04 LTS

pcntl_fork is a php module which will enable the parallel processing and multi threading in php programs. To install it use the below steps:




mkdir /tmp/phpsource

cd /tmp/phpsource

apt-get source php5

cd /tmp/phpsource/php5-*/ext/pcntl

apt-get install php5-dev

phpize5

./configure 

make

cp /tmp/phpsource/php5-*/ext/pcntl/modules/pcntl.so /usr/lib/php5/20121212/

echo "extension=pcntl.so" >  /etc/php5/cli/conf.d/pcntl.ini

Make sure that pcntl is not added in disable_functions option in any of the php.ini file. I found that it was added in /etc/php5/apache2/php.ini. So I have commented it out as given below:

;disable_functions = pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority

Alternatively you can remove that line from the file.

Now to test whether the pcntl module is enabled, create phpinfo.php file in the document root of your website and add below lines to it.

<?php

// Show all information, defaults to INFO_ALL
phpinfo();

?>

Now to go the website "www.mydomain.com/phpinfo.php"  and make sure that pcntl is showing up in the enabled modules in that page.

NOTE: It is not possible to use pcntl_fork as Apache module. It will result in the following error :

Fatal error: Call to undefined function pcntl_fork()

For more details about this error, go to this post.





1 comment: