如何在 php 中启用 pcntl(同时使用像 Symfony2 这样的框架)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/33036773/
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
How to enable pcntl in php ( while using a framework like Symfony2 )
提问by Oussama
c:\xampp\htdocs\login>php app/console server:start
This command needs the pcntl
extension to run.
此命令需要pcntl
扩展才能运行。
This is the error I get when I try to start the web server in my symfony2
environment..
这是我尝试在我的symfony2
环境中启动 Web 服务器时遇到的错误..
I found a fix, by using the command:
我通过使用以下命令找到了一个修复程序:
$ php app/console server:run
But does someone know why server:start
doesn't work on my desktop? Thanks in advance.
但是有人知道为什么server:start
在我的桌面上不起作用吗?提前致谢。
My goal is to:
我的目标是:
Starting the Web Server
启动 Web 服务器
Running a Symfony application using PHP's built-in web server is as easy as executing the server:start
command:
使用 PHP 的内置 Web 服务器运行 Symfony 应用程序就像执行server:start
命令一样简单:
$ php app/console server:start
回答by Suriyaa
On Windows
在 Windows 上
You can't install pcntl
extension on Windows. Accordingly to the PHP documentation:
您无法pcntl
在 Windows 上安装扩展程序。根据 PHP 文档:
Note:This extension is not available on Windows platforms.
注意:此扩展在 Windows 平台上不可用。
Try using Vagrantor a plain virtual machine with Linux distributions like Ubuntu, Debianor Mint.
尝试使用Vagrant或带有 Linux 发行版(如Ubuntu、Debian或Mint)的普通虚拟机。
On UNIX
在 UNIX 上
First, type in your command line in your home directory:
首先,在您的主目录中输入命令行:
mkdir php
cd php
apt-get source php5
cd php5-(WHATEVER_RELEASE)/ext/pcntl
phpize
./configure
make
Then do this:
然后这样做:
cp modules/pcntl.so /usr/lib/php5/WHEVER_YOUR_SO_FILES_ARE/
echo "extension=pcntl.so" > /etc/php5/conf.d/pcntl.ini
Finished!
完成的!
On Mac
在 Mac 上
Taken from https://stackoverflow.com/a/8432855/5157221!
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 make
is 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 phpize
in 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 ./configure
and make
to build our shared object:
然后我们可以运行./configure
并make
构建我们的共享对象:
pcntl$ ./configure
pcntl$ make
This puts a file called pcntl.so
in 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!
如果你看到了,那就成功了!
Helpful resources
有用的资源
For Windows:
对于 Windows:
For UNIX operating systems:
对于 UNIX 操作系统:
For Mac:
对于 Mac:
- how to enable process control extension (PCNTL) in PHP MAMP?
- https://serverfault.com/questions/158113/installing-pcntl-module-for-php-without-recompiling
- 如何在 PHP MAMP 中启用进程控制扩展(PCNTL)?
- https://serverfault.com/questions/158113/installing-pcntl-module-for-php-without-recompileing
Other informations:
其他信息:
回答by Sasha Pachev
I wrote the following script to install pcntl extension for Apache on our Ubuntu systems, which works at least on Ubuntu 16, and I anticipate will also work on Ubuntu 18, as well as other distros with a similar PHP/Apache packaging/installation layout:
我编写了以下脚本来在我们的 Ubuntu 系统上安装 Apache 的 pcntl 扩展,它至少适用于 Ubuntu 16,我预计也适用于 Ubuntu 18,以及其他具有类似 PHP/Apache 打包/安装布局的发行版:
#! /bin/bash
php_ver=$(php -r 'print(join(".",array_slice(explode(".",phpversion()), 0, 2)));')
php_api_ver=$(php-config --phpapi)
pkg="php$php_ver"
mods_dir=/usr/lib/php/$php_api_ver/
php_conf_dir=/etc/php/$php_ver/apache2/conf.d
set -e
work_dir=/tmp/php-pcntl
rm -rf $work_dir
mkdir -p $work_dir
cd $work_dir
apt-get source $pkg
cd $pkg-$php_ver.*/ext/pcntl
phpize
./configure
make -j 8
sudo cp modules/pcntl.so $mods_dir
echo "extension=pcntl.so" | sudo tee $php_conf_dir/10-pcntl.ini > /dev/null
echo "pcntl extension installed, now restart Apache and make sure it really works"
You will possibly need to take care a few pre-requisites in addition to the regular Apache/PHP install: apt-get install php-dev php-cli
, then edit your /etc/apt/sources.list
and make sure the appropriate deb-src
line is not commented, and run apt-get update
. Then you can just run the script and it should take care of the install. If everything is good, rm -rf /tmp/php-pcntl
- I intentionally left that step out of the script in case something goes wrong and I need to debug the contents of that directory.
除了常规的 Apache/PHP 安装之外,您可能还需要注意一些先决条件:apt-get install php-dev php-cli
,然后编辑您的/etc/apt/sources.list
并确保deb-src
没有注释相应的行,然后运行apt-get update
. 然后你可以运行脚本,它应该负责安装。如果一切顺利,rm -rf /tmp/php-pcntl
我特意将这一步排除在脚本之外,以防出现问题并且我需要调试该目录的内容。
Note that you will need to make sure that your php.ini
does not disable your functions of interest with disable_functions=
. E.g. on Ubuntu 16 pcntl_signal()
along with a few others are disabled with an explicit php.ini
directive.
请注意,您需要确保您php.ini
没有禁用您感兴趣的功能disable_functions=
。例如,在 Ubuntu 16pcntl_signal()
和其他一些系统上,使用显式php.ini
指令禁用。
回答by Jeremy Quick
The php-extension-library githubhas several pcntl.so files which you can easily download for your version of PHP and add to your extensions and .ini.
在PHP扩展库github上有几个pcntl.so文件,你可以方便地下载到您的PHP版本,并添加到您的扩展和.ini。
For example, for php version 7.3.9:
例如,对于 php 版本 7.3.9:
- Download
pcntl.so
from the repo hereor directly here. - Move
pcntl.so
file to extensions (Ex:/Applications/MAMP/bin/php/php7.3.9/lib/php/extensions/no-debug-non-zts-xxxxxxxx
) - Add
extension=pcntl.so
to your.ini