如何在 PHP MAMP 中启用进程控制扩展(PCNTL)?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5230255/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 20:41:52  来源:igfitidea点击:

how to enable process control extension (PCNTL) in PHP MAMP?

phpmamppcntl

提问by Lina


I have MAMP and I need to enable -pcntlon my current MAMP installation. How can I do so?


我有 MAMP,我需要-pcntl在我当前的 MAMP 安装上启用。我怎么能这样做?

Thanks for your help.

谢谢你的帮助。

回答by Jon Cairns

There is a way of compiling PCNTL as an extension and linking it in to an existing PHP build, but it's a bit in-depth.

有一种方法可以将 PCNTL 编译为扩展并将其链接到现有的 PHP 构建中,但这有点深入。

I'm doing the following on Mac OSX Snow Leopard (64bit), with MAMP and PHP version 5.3.6. Remember to change PHP version numbers in the following lines if yours is different!

我在 Mac OSX Snow Leopard(64 位)上使用 MAMP 和 PHP 版本 5.3.6 执行以下操作。如果您的版本不同,请记住在以下行中更改 PHP 版本号!

Please note that makeis required, which isn't installed by default on Mac OSX. You need to install this via Mac developer tools, http://developer.apple.com/unix/

请注意,这make是必需的,默认情况下不会在 Mac OSX 上安装。您需要通过 Mac 开发人员工具安装它,http://developer.apple.com/unix/

First, download a tar of the PHP source code that matches the version you are using in MAMP (e.g. mine is 5.3.6), which you can do at http://www.php.net/releases/. Untar and CD to php-[version]/ext/pcntl, e.g.:

首先,下载与您在 MAMP 中使用的版本相匹配的 PHP 源代码的 tar(例如,我的是 5.3.6),您可以在http://www.php.net/releases/ 上执行此操作。解压和 CD 到php-[version]/ext/pcntl,例如:

$ wget http://museum.php.net/php5/php-5.3.6.tar.gz
$ tar xvf php-5.3.6.tar.gz
$ cd php-5.3.6/ext/pcntl

You then need to run phpizein the pcntl directory, which is a binary file that comes with MAMP:

然后需要phpize在 pcntl 目录下运行,这是一个 MAMP 自带的二进制文件:

pcntl$ /Applications/MAMP/bin/php/php5.3.6/bin/phpize

This creates a bunch of files that are needed for preparing a extension for compiling.

这会创建一堆准备编译扩展所需的文件。

We now need to add some flags to tell it to compile the library with dual 32bit and 64bit architecture, as the MAMP PHP has been built this way. If you don't do this, the compiled shared objects won't work.

我们现在需要添加一些标志来告诉它编译具有双 32 位和 64 位架构的库,因为 MAMP PHP 是这样构建的。如果不这样做,编译的共享对象将无法工作。

pcntl$ MACOSX_DEPLOYMENT_TARGET=10.6
pcntl$ CFLAGS="-arch i386 -arch x86_64 -g -Os -pipe -no-cpp-precomp"
pcntl$ CCFLAGS="-arch i386 -arch x86_64 -g -Os -pipe"
pcntl$ CXXFLAGS="-arch i386 -arch x86_64 -g -Os -pipe"
pcntl$ LDFLAGS="-arch i386 -arch x86_64 -bind_at_load"
pcntl$ export CFLAGS CXXFLAGS LDFLAGS CCFLAGS MACOSX_DEPLOYMENT_TARGET

We can then run ./configureand maketo build our shared object:

然后我们可以运行./configuremake构建我们的共享对象:

pcntl$ ./configure
pcntl$ make

This puts a file called pcntl.soin the modulesdirectory. Copy this file to your MAMP's PHP extensions directory:

这会pcntl.so模块目录中放置一个名为的文件。将此文件复制到 MAMP 的 PHP 扩展目录:

pcntl$ cp modules/pcntl.so /Applications/MAMP/bin/php/php5.3.6/lib/php/extensions/no-debug-non-zts-20090626/

Finally, edit the PHP INI file to include the extension:

最后,编辑 PHP INI 文件以包含扩展名:

$ echo "extension=pcntl.so" >> /Applications/MAMP/bin/php/php5.3.6/conf/php.ini

PCNTL should now be enabled. To check to see whether it has been added, just run:

现在应该启用 PCNTL。要检查它是否已添加,只需运行:

$ /Applications/MAMP/bin/php/php5.3.6/bin/php --ri pcntl

pcntl

pcntl support => enabled

If you see that, it's worked! If anything has gone wrong you can just remove the pcntl.sofile from the MAMP PHP extensions directory and remove the INI setting, and try again.

如果你看到了,那就成功了!如果出现任何问题,您只需pcntl.so从 MAMP PHP 扩展目录中删除该文件并删除 INI 设置,然后重试。

回答by Ian Lewis

If you have 'brew' installed on your MAC then you should be able to do:

如果您的 MAC 上安装了“brew”,那么您应该能够执行以下操作:

brew install php53-pcntl

酿造安装php53-pcntl

I am no expert on MAMP though.

不过,我不是 MAMP 方面的专家。

==== EDIT ==== (In response to being down voted)

==== 编辑 ==== (响应被否决)

Ian-Lewiss-MacBook-Pro:~ ianlewis$ brew install php53-pcntl
Warning: php53-pcntl-5.3.25 already installed

Ian-Lewiss-MacBook-Pro:~ ianlewis$ brew info php53-pcntl
php53-pcntl: stable 5.3.25
http://php.net/manual/en/book.pcntl.php
/usr/local/Cellar/php53-pcntl/5.3.23 (3 files, 32K)
  Built from source
/usr/local/Cellar/php53-pcntl/5.3.25 (3 files, 32K) *
  Built from source
https://github.com/josegonzalez/homebrew-php/commits/master/Formula/php53-pcntl.rb
==> Dependencies
Build: autoconf
Required: php53
==> Options
--without-config-file
    Do not add ext-pcntl.ini to /usr/local/etc/php/5.3/conf.d
--without-homebrew-php
    Ignore homebrew PHP and use default instead
==> Caveats
To finish installing pcntl for PHP 5.3:
  * /usr/local/etc/php/5.3/conf.d/ext-pcntl.ini was created,
    do not forget to remove it upon extension removal.
  * Restart your webserver.
  * Write a PHP page that calls "phpinfo();"
  * Load it in a browser and look for the info on the pcntl module.
  * If you see it, you have been successful!

回答by rp90

Just to make my life easier I made a script from the other post. I used it to add extensions pcntl, sysvmsg, sysvshm, sysvsem and others to MAMP. To use cd to the extension directory or pass the directory as an argument to the script. Example ./addExtension.sh php-5.3.6/ext/pcntl

为了让我的生活更轻松,我从另一篇文章中制作了一个脚本。我用它来向 MAMP 添加扩展 pcntl、sysvmsg、sysvshm、sysvsem 和其他扩展。使用 cd 到扩展目录或将目录作为参数传递给脚本。示例 ./addExtension.sh php-5.3.6/ext/pcntl

#!/bin/bash
DIR=
MAMP_PHP=
if [ -z "$DIR" ]
then
  DIR=`pwd`
fi

if [ -z "$MAMP_PHP" ]
then
  MAMP_PHP='/Applications/MAMP/bin/php/php5.3.6'
fi

EXTENSION=${DIR##*/}

echo Extension: $EXTENSION  

cd $DIR

eval "${MAMP_PHP}/bin/phpize"


MACOSX_DEPLOYMENT_TARGET=10.6
CFLAGS="-arch i386 -arch x86_64 -g -Os -pipe -no-cpp-precomp"
CCFLAGS="-arch i386 -arch x86_64 -g -Os -pipe"
CXXFLAGS="-arch i386 -arch x86_64 -g -Os -pipe"
LDFLAGS="-arch i386 -arch x86_64 -bind_at_load"
export CFLAGS CXXFLAGS LDFLAGS CCFLAGS MACOSX_DEPLOYMENT_TARGET

./configure
make

cp modules/${EXTENSION}.so "${MAMP_PHP}/lib/php/extensions/no-debug-non-zts-20090626/"

PHP_INI_PATH="${MAMP_PHP}/conf/php.ini"
sed -e "/extension=${EXTENSION}.so/ d" $PHP_INI_PATH > TMP
mv TMP $PHP_INI_PATH
echo "extension=${EXTENSION}.so" >> $PHP_INI_PATH

eval "${MAMP_PHP}/bin/php --ri ${EXTENSION}"

回答by padawan

I solved the problem by using MacPorts.

我通过使用 MacPorts 解决了这个问题。

Ran the command:

运行命令:

sudo port install php5-pcntl

回答by davydka

I found some slightly different instructions that worked for Yosemite and Mamp using php 5.6.2. Instructions were found here: https://www.flynsarmy.com/2015/01/get-artisan-tinker-working-osx-10-mamp/

我发现了一些使用 php 5.6.2 对 Yosemite 和 Mamp 工作的指令略有不同。在此处找到说明:https: //www.flynsarmy.com/2015/01/get-artisan-tinker-working-osx-10-mamp/

wget http://museum.php.net/php5/php-5.6.2.tar.gz
tar -xzvf php-5.6.2.tar.gz
mv php-5.6.2 php
mkdir -p /Applications/MAMP/bin/php/php5.6.2/include
mv php /Applications/MAMP/bin/php/php5.6.2/include

cd /Applications/MAMP/bin/php/php5.6.2/include/php
./configure

MACOSX_DEPLOYMENT_TARGET=10.10
CFLAGS="-arch i386 -arch x86_64 -g -Os -pipe -no-cpp-precomp"
CCFLAGS="-arch i386 -arch x86_64 -g -Os -pipe"
CXXFLAGS="-arch i386 -arch x86_64 -g -Os -pipe"
LDFLAGS="-arch i386 -arch x86_64 -bind_at_load"
export CFLAGS CXXFLAGS LDFLAGS CCFLAGS MACOSX_DEPLOYMENT_TARGET

cd ext/pcntl
phpize
./configure
make
cp modules/pcntl.so /Applications/MAMP/bin/php/php5.6.2/lib/php/extensions/no-debug-non-zts-20131226

回答by Abouhassane Abdelhamid

  1. download php from https://www.php.net/releases/
  2. tar -xzvf php-7.3.8.tar.gz(We will name the outputed folder PhpSrcFolder)
  3. Make sure you've got the MAMP bin directory in your path => echo $PATH. You'll need the extra tools it has in order to do this. (Skip to step 5 if you already have mamp's bin in you $PATH)
  4. you can add mamp's bin to your path as follow, we first grep the version of php's used by mamp from ~/.profile(PS: Mamp add alias to php in the latter), then we add the mamp bin to PATH in accordance with the version used.
  1. https://www.php.net/releases/下载 php
  2. tar -xzvf php-7.3.8.tar.gz(我们将命名输出文件夹PhpSrcFolder
  3. 确保您的路径 => 中有 MAMP bin 目录echo $PATH。您将需要它拥有的额外工具才能做到这一点。(如果 $PATH 中已经有 mamp 的 bin,请跳到第 5 步)
  4. 您可以将mamp的bin添加到您的路径中,我们首先grep mamp使用的php版本~/.profile(PS:Mamp在后者中为php添加别名),然后我们根据使用的版本将mamp bin添加到PATH。

export PHP_VERSION=grep "alias php" ~/.profile | cut -d"/" -f6 | cut -c4-

# point to your php.ini folder to use the same php setting

export PHPRC="/Library/Application Support/appsolute/MAMP PRO/conf/"

export PATH=/Applications/MAMP/bin/php/php$PHP_VERSION/bin:$PATH

导出 PHP_VERSION=grep "alias php" ~/.profile | cut -d"/" -f6 | cut -c4-

# 指向您的 php.ini 文件夹以使用相同的 php 设置

导出 PHPRC="/Library/Application Support/appsolute/MAMP PRO/conf/"

导出路径=/Applications/MAMP/bin/php/php$PHP_VERSION/bin:$PATH

PS: close and reopen terminal

PS:关闭并重新打开终端

  1. Copy PhpSrcFolder/ext/pcntl to /Applications/MAMP/bin/php/php7.3.8/include/php/ext/pcntl

  2. Go into /Applications/MAMP/bin/php/php7.3.8/include/php/ext/pcntland then run the phpizecommand. Note that you'll also need to have Xcode and related tools installed.

  3. You should then be able to run ./configure && make && make install. This will build the extension in /Applications/MAMP/bin/php/php7.3.8/include/php/ext/pcntl/modules/pcntl.so, copy it and paste it in /Applications/MAMP/bin/php/php7.3.8/lib/php/extensions/no-debug-non-zts-20180731/pcntl.so

  4. Now, edit the php.ini and enable the module like you would any of the other extensions. get path of php.iniloaded by runing which phpfor me its : /Library/Application Support/appsolute/MAMP PRO/conf/php7.3.8.iniand recheck that it has the pcntl extension:

  1. 复制PhpSrcFolder/ext/pcntl 到/Applications/MAMP/bin/php/php7.3.8/include/php/ext/pcntl

  2. 进入/Applications/MAMP/bin/php/php7.3.8/include/php/ext/pcntl然后运行phpize命令。请注意,您还需要安装 Xcode 和相关工具。

  3. 然后您应该能够运行./configure && make && make install. 这将在 中构建扩展/Applications/MAMP/bin/php/php7.3.8/include/php/ext/pcntl/modules/pcntl.so,将其复制并粘贴到/Applications/MAMP/bin/php/php7.3.8/lib/php/extensions/no-debug-non-zts-20180731/pcntl.so

  4. 现在,编辑 php.ini 并像启用其他任何扩展一样启用该模块。php.ini通过which php为我运行它来获取加载路径:/Library/Application Support/appsolute/MAMP PRO/conf/php7.3.8.ini并重新检查它是否具有 pcntl 扩展名:

[pcntl]

extension=pcntl.so

[pcntl]

扩展名=pcntl.so