I’m getting this PHP Warning:
Module ‘pcntl’ already loaded in Unknown on line 0
But it is only enabled for Apache. Enabled it on /etc/php/7.2/apache2/conf.d/20-pcntl.ini
:
extension=pcntl.so
I don’t have it enabled on CLI. Checked with:
- I don’t have a
/etc/php/7.2/cli/conf.d/20-pcntl.ini
file - Grep command
grep -R extension=pcntl.so /etc/php/7.2
only returns the file on apache2 folder
If I disable this extension on Apache’s .ini, it won’t load on Apache but loads on Cli.
If I enable this extension on Apache’s .ini, I get the module already loaded warning.
I’m need to enable PCNTL on Apache to use SpatieAsync library.
It’s a Ubuntu 14 server.
2
Answers
Sometimes extensions are compiled into PHP rather than loaded as separate modules. Before fiddling with the PHP.ini files, you should probably run a quick PHP script to see what modules are loaded:
You should also beware of PHP directives like disable_functions which may be disabling the pcntl functions. On my Ubuntu workstation, the pcntl functions are disabled with this directive:
I suggest you try a broader grep search to see if pcntl gets mentioned in other places:
That seems a bit weird to me. You might try searching for more php.ini files there:
You should also check to make sure that you aren’t running a different PHP from the command line than you are with apache. Under certain circumstances (which regrettably happen more often that you might think) your CLI PHP is different than your Apache PHP. This article discusses that issue in more detail.
That actually sounds reasonable to me. If I had to guess, I would say that the wise Ubuntu/Debian package manager folks decided it would be unwise to allow pcntl_x functions to run in an apache environment, especially given this stark and ancient warning. I don’t recall if that warning is outdated now or not. I would refer you to this other thread where I asked some related questions and was told I should use PHP-FPM with apache in event mode.
All that said, I have had some tremendous success writing “multithreaded” applications in PHP (technically not multithreaded but rather multiprocessing) using pcntl_fork and posix_setsid and the like.
To summarize, I’m guessing that PCNTL is already loaded both on apache and cli and the wise Ubuntu devs probably disabled the pcntl functions in the php.ini.
I know this is long after the original post, but I faced a similar problem. I’m working on a AWS Linux AMI and pnctl seems to be pre-installed into php-cli (not loaded via php.ini)
The problem is Spatie async checks your PHP Runtime (PHP-FPM) to see if the pnctl and posix modules are loaded, which by default aren’t even though they are available in php-cli which it actually uses when you create Spatie Async Pools.
My solution was to actually modify the php-fpm service to run with
extension=pnctl.so
It will create an override file in
/etc/systemd/system/
Modify the file by changing
ExecStart=/usr/sbin/php-fpm --nodaemonize
toExecStart=/usr/sbin/php-fpm -d extension=pctnl.so--nodaemonize
and save thatThen restart your nginx and php-fpm services and pnctl should be active for PHP-FPM