skip to Main Content

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


  1. 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:

    <?php
    var_dump(get_loaded_extensions());
    

    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:

    /etc/php5/apache2/php.ini: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
    

    I suggest you try a broader grep search to see if pcntl gets mentioned in other places:

    grep -ir pcntl.so /etc/php/7.2
    

    I don’t have a /etc/php/7.2/cli/conf.d/20-pcntl.ini file

    That seems a bit weird to me. You might try searching for more php.ini files there:

    sudo find /etc -name "php.ini"
    

    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.

    If I disable this extension on Apache’s .ini, it won’t load on Apache but loads on Cli.

    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.

    Login or Signup to reply.
  2. 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

    systemctl edit php-fpm
    

    It will create an override file in /etc/systemd/system/

    Modify the file by changing

    ExecStart=/usr/sbin/php-fpm --nodaemonize to ExecStart=/usr/sbin/php-fpm -d extension=pctnl.so--nodaemonize and save that

    Then restart your nginx and php-fpm services and pnctl should be active for PHP-FPM

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search