如何为 PHP 7.4 及更高版本编译 pcntl?

How to compile pcntl for PHP 7.4 and above?

我正在尝试使用以下命令(来自 Mac)为 PHP 7.4 和 PHP 8 编译 pcntl 扩展:

wget "https://www.php.net/distributions/php-7.4.0.tar.gz"
tar xvf "php-7.4.0.tar.gz"
cd "php-7.4.0/ext/pcntl/"
phpize
./configure
make

但是,对于 PHP >7.3 的每个版本,make 命令都会抛出以下错误:

      [-Werror,-Wimplicit-function-declaration]
                z_rusage = zend_try_array_init(z_rusage);
                           ^
/Users/jrquick/development/encounting/php-extension-library/php-7.4.10/ext/pcntl/pcntl.c:721:12: warning: incompatible integer to pointer conversion assigning to 'zval *'
      (aka 'struct _zval_struct *') from 'int' [-Wint-conversion]
                z_rusage = zend_try_array_init(z_rusage);
                         ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/jrquick/development/encounting/php-extension-library/php-7.4.10/ext/pcntl/pcntl.c:745:2: error: implicit declaration of function 'ZEND_TRY_ASSIGN_REF_LONG' is invalid in C99
      [-Werror,-Wimplicit-function-declaration]
        ZEND_TRY_ASSIGN_REF_LONG(z_status, status);
        ^
/Users/jrquick/development/encounting/php-extension-library/php-7.4.10/ext/pcntl/pcntl.c:770:14: error: implicit declaration of function 'zend_try_array_init' is invalid in C99
      [-Werror,-Wimplicit-function-declaration]
                z_rusage = zend_try_array_init(z_rusage);
                           ^
/Users/jrquick/development/encounting/php-extension-library/php-7.4.10/ext/pcntl/pcntl.c:770:12: warning: incompatible integer to pointer conversion assigning to 'zval *'
      (aka 'struct _zval_struct *') from 'int' [-Wint-conversion]
                z_rusage = zend_try_array_init(z_rusage);
                         ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/jrquick/development/encounting/php-extension-library/php-7.4.10/ext/pcntl/pcntl.c:795:2: error: implicit declaration of function 'ZEND_TRY_ASSIGN_REF_LONG' is invalid in C99
      [-Werror,-Wimplicit-function-declaration]
        ZEND_TRY_ASSIGN_REF_LONG(z_status, status);
        ^
/Users/jrquick/development/encounting/php-extension-library/php-7.4.10/ext/pcntl/pcntl.c:979:9: error: implicit declaration of function 'try_convert_to_string' is invalid in C99
      [-Werror,-Wimplicit-function-declaration]
                        if (!try_convert_to_string(element)) {
                             ^
/Users/jrquick/development/encounting/php-extension-library/php-7.4.10/ext/pcntl/pcntl.c:979:9: note: did you mean '_convert_to_string'?
/usr/local/Cellar/php/7.3.11/include/php/Zend/zend_operators.h:249:29: note: '_convert_to_string' declared here
ZEND_API void ZEND_FASTCALL _convert_to_string(zval *op);
                            ^
/Users/jrquick/development/encounting/php-extension-library/php-7.4.10/ext/pcntl/pcntl.c:1010:9: error: implicit declaration of function 'try_convert_to_string' is invalid in C99
      [-Werror,-Wimplicit-function-declaration]
                        if (!try_convert_to_string(element)) {
                             ^
/Users/jrquick/development/encounting/php-extension-library/php-7.4.10/ext/pcntl/pcntl.c:1197:17: error: implicit declaration of function 'zend_try_array_init' is invalid in C99
      [-Werror,-Wimplicit-function-declaration]
                user_oldset = zend_try_array_init(user_oldset);
                              ^
/Users/jrquick/development/encounting/php-extension-library/php-7.4.10/ext/pcntl/pcntl.c:1197:15: warning: incompatible integer to pointer conversion assigning to 'zval *'
      (aka 'struct _zval_struct *') from 'int' [-Wint-conversion]
                user_oldset = zend_try_array_init(user_oldset);
                            ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/jrquick/development/encounting/php-extension-library/php-7.4.10/ext/pcntl/pcntl.c:1295:18: error: implicit declaration of function 'zend_try_array_init' is invalid in C99
      [-Werror,-Wimplicit-function-declaration]
                user_siginfo = zend_try_array_init(user_siginfo);
                               ^
/Users/jrquick/development/encounting/php-extension-library/php-7.4.10/ext/pcntl/pcntl.c:1295:16: warning: incompatible integer to pointer conversion assigning to 'zval *'
      (aka 'struct _zval_struct *') from 'int' [-Wint-conversion]
                user_siginfo = zend_try_array_init(user_siginfo);

如何解决此错误或获取 pcntl.so 的编译版本?

同样的过程适用于 PHP 4 到 PHP 7.3

下载最新的 MAMP 版本(包括 PHP 7.4.10 和 PHP 8)。

然后改成./configure

  • PHP 7.4.*: ./configure --with-php-config=/Applications/MAMP/bin/php/php7.4.12/bin/php-config
  • PHP8.*:--with-php-config=/Applications/MAMP/bin/php/php8.0.0/bin/php-config

之后我的 make 命令成功 运行 并生成了预期的 pcntl.so 文件。

完整命令:

wget "https://www.php.net/distributions/php-7.4.0.tar.gz"
tar xvf "php-7.4.0.tar.gz"
cd "php-7.4.0/ext/pcntl/"
phpize
./configure --with-php-config=/Applications/MAMP/bin/php/php7.4.12/bin/php-config
make